From b6e15e047d7f981cbd987e60a1adcf62a57010a1 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 18 Mar 2014 12:56:10 +0100 Subject: [PATCH] QMenu: Enable sloppy submenu mouse navigation Since we're in the 21st century, we set QCommonStyle to return true to the SH_Menu_SloppySubMenus style hint. This unlocks all the logic already available in QMenu. This is a backport of I134c87e348d98d1f46055e0bfef2b4a4a3d2993a from qt/qtbase and includes some previous enhancements. Task-number: QTBUG-20094 [ChangeLog][QtWidgets][QMenu] Enable sloppy submenu mouse navigation Change-Id: If4141a3d849123850e40af92ac5aede9ed767bdf Reviewed-by: J-P Nurmi Reviewed-by: Lars Knoll --- src/gui/styles/qcommonstyle.cpp | 4 ++++ src/gui/styles/qmacstyle_mac.mm | 3 --- src/gui/styles/qstyle.cpp | 6 ++++-- src/gui/widgets/qmenu.cpp | 10 ++++++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 1645152..c204633 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -4931,6 +4931,10 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget ret = 256; break; + case SH_Menu_SloppySubMenus: + ret = true; + break; + case SH_ProgressDialog_TextLabelAlignment: ret = Qt::AlignCenter; break; diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm index a93d987..a575b31 100644 --- a/src/gui/styles/qmacstyle_mac.mm +++ b/src/gui/styles/qmacstyle_mac.mm @@ -2392,9 +2392,6 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w ret = QDialogButtons::Reject; break; */ - case SH_Menu_SloppySubMenus: - ret = true; - break; case SH_GroupBox_TextLabelVerticalAlignment: ret = Qt::AlignTop; break; diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp index 558153f..5a86d9b 100644 --- a/src/gui/styles/qstyle.cpp +++ b/src/gui/styles/qstyle.cpp @@ -1681,8 +1681,10 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value SH_Menu_Scrollable Whether popup menus must support scrolling. - \value SH_Menu_SloppySubMenus Whether popupmenu's must support - sloppy submenu; as implemented on Mac OS. + \value SH_Menu_SloppySubMenus Whether popup menus must support + the user moving the mouse cursor to a submenu while crossing + other items of the menu. This is supported on most modern + desktop platforms. \value SH_ScrollView_FrameOnlyAroundContents Whether scrollviews draw their frame only around contents (like Motif), or around diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index 2a7477a..0e4ecde 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -2872,8 +2872,14 @@ void QMenu::mouseMoveEvent(QMouseEvent *e) d->mouseDown = this; } if (d->sloppyRegion.contains(e->pos())) { - d->sloppyAction = action; - d->sloppyDelayTimer = startTimer(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)*6); + if (d->sloppyAction != action && d->sloppyDelayTimer != 0) { + killTimer(d->sloppyDelayTimer); + d->sloppyDelayTimer = 0; + } + if (d->sloppyDelayTimer == 0) { + d->sloppyAction = action; + d->sloppyDelayTimer = startTimer(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)*6); + } } else if (action != d->currentAction) { d->setCurrentAction(action, style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)); } -- 2.1.4