aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2024-04-24 17:19:47 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2024-04-26 08:56:44 +0200
commitbe3fc8ced3aba2a0d564f58719306ac52d31a51d (patch)
treeb4b629e609f7cbf665d055b218c0d071f6b14b23
parentc270c59f93cd1bf07221e0e678ca56a70e5daeb4 (diff)
MenuBar: open the popup underneath the MenuBarItemwip/nativemenus
On all tested platforms, except macOS, the drop down menu should open directly underneath the menu bar item, and not the menu bar itself. Change-Id: I4574032ab0f0d6d2481fb91d45d29d7435338b91 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates/qquickmenubar.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/quicktemplates/qquickmenubar.cpp b/src/quicktemplates/qquickmenubar.cpp
index 3c1c11d801..6bb2799f35 100644
--- a/src/quicktemplates/qquickmenubar.cpp
+++ b/src/quicktemplates/qquickmenubar.cpp
@@ -118,14 +118,26 @@ bool QQuickMenuBarPrivate::isCurrentMenuOpen()
void QQuickMenuBarPrivate::openCurrentMenu()
{
- Q_Q(QQuickMenuBar);
if (!currentItem || isCurrentMenuOpen())
return;
QQuickMenu *menu = currentItem->menu();
if (!menu || menu->isOpened())
return;
+
+#ifdef Q_OS_MACOS
+ // On macOS, the menu should open underneath the MenuBar
+ Q_Q(QQuickMenuBar);
+ const QPointF posInParentItem = q->mapToItem(currentItem, {currentItem->x(), q->height()});
+#else
+ // On other platforms, it should open underneath the MenuBarItem
+ const QPointF posInParentItem{0, currentItem->y() + currentItem->height()};
+#endif
+
+ // The position should be the coordinate system of the parent item. Note that
+ // the parentItem() of a menu will be the MenuBarItem (currentItem), and not the
+ // MenuBar (even if parent() usually points to the MenuBar).
QScopedValueRollback triggerRollback(triggering, true);
- menu->popup({0, q->height()});
+ menu->popup(posInParentItem);
}
void QQuickMenuBarPrivate::closeCurrentMenu()