summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Cota <igor@codexapertus.com>2012-10-10 16:15:42 +0200
committerJens Bache-Wiig <jens.bache-wiig@digia.com>2012-10-11 13:11:55 +0200
commit8f98e54eb3fe72e381210bf3a8362854c2017b35 (patch)
treeb62b897db7cc315c79fb8aa8447016da36841f13
parentead5449f57cc6cff6f4ca1d2df851ebd06a4cb83 (diff)
downloadqtquickcontrols-8f98e54eb3fe72e381210bf3a8362854c2017b35.tar.gz
Fix QMenu coordinates when showing popup
Change-Id: I32f15ec4ec3d988f7aa0c18462b50611611df530 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
-rw-r--r--src/qtmenu.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/qtmenu.cpp b/src/qtmenu.cpp
index c430eff6..1c5dc259 100644
--- a/src/qtmenu.cpp
+++ b/src/qtmenu.cpp
@@ -106,16 +106,11 @@ void QtMenu::showPopup(qreal x, qreal y, int atActionIndex)
atAction = m_qmenu->actions()[atActionIndex];
// x,y are in view coordinates, QMenu expects screen coordinates
- // ### activeWindow hack
- int menuBarHeight = 0;
- QWidget *window = QApplication::activeWindow();
- QTopLevelWindow *tw = qobject_cast<QTopLevelWindow*>(window);
- if (tw) {
- QMenuBar *menuBar = tw->menuBar();
- menuBarHeight = menuBar->height();
- }
-
- QPoint screenPosition = window->mapToGlobal(QPoint(x, y+menuBarHeight));
+ // map coordinates from focusWidget rather than activeWindow since
+ // QML items are commonly presented through a QWidget-derived view
+ // still a hack
+ QWidget *focusedWidget = QApplication::focusWidget();
+ QPoint screenPosition = focusedWidget->mapToGlobal(QPoint(x, y));
setHoveredIndex(m_selectedIndex);
m_qmenu->popup(screenPosition, atAction);