diff options
Diffstat (limited to 'src/widgets/widgets/qmenu.cpp')
-rw-r--r-- | src/widgets/widgets/qmenu.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 167a10efc3..58212a737a 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -260,7 +260,7 @@ int QMenuPrivate::scrollerHeight() const return qMax(QApplication::globalStrut().height(), q->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, q)); } -//Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't +//Windows and KDE allow menus to cover the taskbar, while GNOME and Mac don't QRect QMenuPrivate::popupGeometry(const QWidget *widget) const { if (QGuiApplicationPrivate::platformTheme() && @@ -271,7 +271,7 @@ QRect QMenuPrivate::popupGeometry(const QWidget *widget) const } } -//Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't +//Windows and KDE allow menus to cover the taskbar, while GNOME and Mac don't QRect QMenuPrivate::popupGeometry(int screen) const { if (QGuiApplicationPrivate::platformTheme() && @@ -297,6 +297,11 @@ QVector<QPointer<QWidget> > QMenuPrivate::calcCausedStack() const return ret; } +bool QMenuPrivate::isContextMenu() const +{ + return qobject_cast<const QMenuBar *>(topCausedWidget()) == nullptr; +} + void QMenuPrivate::updateActionRects() const { Q_Q(const QMenu); @@ -352,6 +357,7 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const //calculate size QFontMetrics qfm = q->fontMetrics(); bool previousWasSeparator = true; // this is true to allow removing the leading separators + const bool contextMenu = isContextMenu(); for(int i = 0; i <= lastVisibleAction; i++) { QAction *action = actions.at(i); const bool isSection = action->isSeparator() && (!action->text().isEmpty() || !action->icon().isNull()); @@ -383,7 +389,7 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const tabWidth = qMax(int(tabWidth), qfm.width(s.mid(t+1))); s = s.left(t); #ifndef QT_NO_SHORTCUT - } else { + } else if (action->isShortcutVisibleInContextMenu() || !contextMenu) { QKeySequence seq = action->shortcut(); if (!seq.isEmpty()) tabWidth = qMax(int(tabWidth), qfm.width(seq.toString(QKeySequence::NativeText))); @@ -1513,7 +1519,8 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) option->icon = action->icon(); QString textAndAccel = action->text(); #ifndef QT_NO_SHORTCUT - if (textAndAccel.indexOf(QLatin1Char('\t')) == -1) { + if ((action->isShortcutVisibleInContextMenu() || !d->isContextMenu()) + && textAndAccel.indexOf(QLatin1Char('\t')) == -1) { QKeySequence seq = action->shortcut(); if (!seq.isEmpty()) textAndAccel += QLatin1Char('\t') + seq.toString(QKeySequence::NativeText); @@ -2423,8 +2430,6 @@ void QMenu::popup(const QPoint &p, QAction *atAction) pos.setY(qMin(mouse.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1)); else pos.setY(qMax(p.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1)); - } else if (pos.y() < screen.top() + desktopFrame) { - pos.setY(screen.top() + desktopFrame); } if (pos.y() < screen.top() + desktopFrame) @@ -2656,7 +2661,8 @@ void QMenu::hideEvent(QHideEvent *) if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget)) mb->d_func()->setCurrentAction(0); #endif - d->mouseDown = 0; + if (d->mouseDown == this) + d->mouseDown = 0; d->hasHadMouse = false; if (d->activeMenu) d->hideMenu(d->activeMenu); |