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 <richard.gustavsen@qt.io>
bb10
Gabriel de Dietrich 2018-03-13 19:43:15 -07:00
parent 2fb706f9a8
commit 0c059db57d
1 changed files with 7 additions and 0 deletions

View File

@ -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);