path: root/src/widgets
diff options
authorGabriel de Dietrich <>2015-03-10 16:22:58 +0100
committerGabriel de Dietrich <>2015-03-11 17:04:59 +0000
commit22afbc153628348bc6d4ee0655ea6a6584a13322 (patch)
treec30f4250fd301bc2103839612bb48d0003d27d7a /src/widgets
parenta4c2e95ce16b3c4f9e0c9c983fb1ce9e70b5ce5a (diff)
QShortCut: Check whether the menu is QPA-disabled
When climbing the menu hierarchy, it's sounder to check whether the actual QPA menu is enabled. This way we can trigger modifier-less shortcuts even in submenus. Task-number: QTBUG-38256 Task-number: QTBUG-42584 Change-Id: I13a27027306bce0f0732b05bf9469f3b77028f73 Reviewed-by: Liang Qi <>
Diffstat (limited to 'src/widgets')
1 files changed, 8 insertions, 3 deletions
diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp
index c4326aaa5a..c08c4eeb32 100644
--- a/src/widgets/kernel/qshortcut.cpp
+++ b/src/widgets/kernel/qshortcut.cpp
@@ -44,6 +44,7 @@
#include <private/qshortcutmap_p.h>
#include <private/qaction_p.h>
#include <private/qwidgetwindow_p.h>
+#include <qpa/qplatformmenu.h>
@@ -269,9 +270,13 @@ static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidge
// On Mac, menu item shortcuts are processed before reaching any window.
// That means that if a menu action shortcut has not been already processed
// (and reaches this point), then the menu item itself has been disabled.
- // This occurs at the QPA level on Mac, were we disable all the Cocoa menus
- // when showing a modal window.
- if (a->shortcut().count() < 1 || (a->shortcut().count() == 1 && (a->shortcut()[0] & Qt::MODIFIER_MASK) != 0))
+ // This occurs at the QPA level on Mac, where we disable all the Cocoa menus
+ // when showing a modal window. (Notice that only the QPA menu is disabled,
+ // not the QMenu.) Since we can also reach this code by climbing the menu
+ // hierarchy (see below), or when the shortcut is not a key-equivalent, we
+ // need to check whether the QPA menu is actually disabled.
+ QPlatformMenu *pm = menu->platformMenu();
+ if (!pm || !pm->isEnabled())
QAction *a = menu->menuAction();