summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/kernel/qshortcut.cpp4
-rw-r--r--tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp28
2 files changed, 31 insertions, 1 deletions
diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp
index 0585a59e89..f944a7097b 100644
--- a/src/widgets/kernel/qshortcut.cpp
+++ b/src/widgets/kernel/qshortcut.cpp
@@ -289,8 +289,10 @@ static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidge
// 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.
+ // When there is no QPA menu, there will be no QCocoaMenuDelegate checking
+ // for the actual shortcuts. We can then fallback to our own logic.
QPlatformMenu *pm = menu->platformMenu();
- if (!pm || !pm->isEnabled())
+ if (pm && !pm->isEnabled())
continue;
#endif
QAction *a = menu->menuAction();
diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
index f0fb7bc367..ad30db501a 100644
--- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
+++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
@@ -133,6 +133,7 @@ private slots:
void menuSize_Scrolling_data();
void menuSize_Scrolling();
void tearOffMenuNotDisplayed();
+ void QTBUG_61039_menu_shortcuts();
protected slots:
void onActivated(QAction*);
@@ -1609,5 +1610,32 @@ void tst_QMenu::tearOffMenuNotDisplayed()
QVERIFY(!torn->isVisible());
}
+void tst_QMenu::QTBUG_61039_menu_shortcuts()
+{
+ QAction *actionKamen = new QAction("Action Kamen");
+ actionKamen->setShortcut(QKeySequence(QLatin1String("K")));
+
+ QAction *actionJoe = new QAction("Action Joe");
+ actionJoe->setShortcut(QKeySequence(QLatin1String("Ctrl+J")));
+
+ QMenu menu;
+ menu.addAction(actionKamen);
+ menu.addAction(actionJoe);
+ QVERIFY(!menu.platformMenu());
+
+ QWidget widget;
+ widget.addAction(menu.menuAction());
+ widget.show();
+ QVERIFY(QTest::qWaitForWindowActive(&widget));
+
+ QSignalSpy actionKamenSpy(actionKamen, &QAction::triggered);
+ QTest::keyClick(&widget, Qt::Key_K);
+ QTRY_COMPARE(actionKamenSpy.count(), 1);
+
+ QSignalSpy actionJoeSpy(actionJoe, &QAction::triggered);
+ QTest::keyClick(&widget, Qt::Key_J, Qt::ControlModifier);
+ QTRY_COMPARE(actionJoeSpy.count(), 1);
+}
+
QTEST_MAIN(tst_QMenu)
#include "tst_qmenu.moc"