From 0c059db57d47cb20bf069fce3e444f9eb8e9f33c Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 13 Mar 2018 19:43:15 -0700 Subject: QMenu: Realign submenu first action with its parent menu action There was an offset equivalent to all the margins we add to the action rectangles. We need to subtract it in order for both menu items, parent and sub-menu, to be aligned. This amount is given by the sub-menu's first action position relative to its popup. Change-Id: I141bbe3cfb81825a25b12e4059b93e61c29df518 Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmenu.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 024f9a75a1..363647aee0 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -3641,6 +3641,13 @@ void QMenu::internalDelayedPopup() if (subMenuPos.x() > screen.right()) subMenuPos.setX(QCursor::pos().x()); + const auto &subMenuActions = d->activeMenu->actions(); + if (!subMenuActions.isEmpty()) { + // Offset by the submenu's 1st action position to align with the current action + const auto subMenuActionRect = d->activeMenu->actionGeometry(subMenuActions.first()); + subMenuPos.ry() -= subMenuActionRect.top(); + } + d->activeMenu->popup(subMenuPos); d->sloppyState.setSubMenuPopup(actionRect, d->currentAction, d->activeMenu); -- cgit v1.2.3