summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorVlad Zahorodnii <[email protected]>2025-01-29 22:49:15 +0200
committerVlad Zahorodnii <[email protected]>2025-06-18 22:26:23 +0200
commitc6779c7252bf5690305eba9646b9259f24f5b5fb (patch)
treed9dd8cb33e18eb74819fd4bfe23f8ed791ba0361 /tests/auto
parent68210484d95b0f944092c1380aafa7325c9ca891 (diff)
tst_QShortcut: Test that modifier only shortcuts are not triggered
The QShortcutMap triggers shortcuts on key press. It's okay with normal shortcuts but modifier only shortcuts require extra care. Depending on the context, they can be triggered either on key press or key release. For example, for push to talk, they should be triggered on key press, but if a modifier only shortcut is assigned to a dashboard or something, then it should be triggered on key release so the dashboard is not accidentally opened when pressing another shortcut that starts with the same modifier. The QShortcutMap currently doesn't provide support for modifier only shortcuts. The proposed new test case verifies that a modifier only shortcut will not be accidentally triggered if there is a normal shortcut with the same modifier keys. Task-number: QTBUG-132435 Change-Id: I612d0239b29f8c1730016d10257def039b5e6cf1 Reviewed-by: Tor Arne Vestbø <[email protected]>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
index 3a94e1833a0..317bc3f6ca6 100644
--- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
@@ -158,6 +158,7 @@ private slots:
void shortcutToFocusProxy();
void deleteLater();
void keys();
+ void modifierOnly();
protected:
static Qt::KeyboardModifiers toButtons( int key );
@@ -1356,5 +1357,42 @@ void tst_QShortcut::keys()
QTRY_COMPARE(spy.size(), 2);
}
+void tst_QShortcut::modifierOnly()
+{
+ MainWindow mainW;
+ const QString name = QLatin1String(QTest::currentTestFunction());
+ mainW.setWindowTitle(name);
+ mainW.show();
+ mainW.activateWindow();
+ QVERIFY(QTest::qWaitForWindowActive(&mainW));
+
+ const QKeyCombination altModifier(Qt::AltModifier);
+ const QKeyCombination altKey(Qt::Key_Alt);
+ const QKeyCombination altModifierPlusK(Qt::AltModifier | Qt::Key_K);
+
+ QShortcut *altModifierShortcut = setupShortcut(&mainW, name, altModifier);
+ QSignalSpy altModifierActivated(altModifierShortcut, &QShortcut::activated);
+ QShortcut *altModifierPlusKShortcut = setupShortcut(&mainW, name, altModifierPlusK);
+ QSignalSpy altModifierPlusKActivated(altModifierPlusKShortcut, &QShortcut::activated);
+ QShortcut *altKeyShortcut = setupShortcut(&mainW, name, altKey);
+ QSignalSpy altKeyActivated(altKeyShortcut, &QShortcut::activated);
+
+ // modifier only shortcuts are unsupported
+ sendKeyEvents(&mainW, altModifier);
+ QCOMPARE(altModifierActivated.size(), 0);
+ QCOMPARE(altKeyActivated.size(), 0);
+ QCOMPARE(altModifierPlusKActivated.size(), 0);
+
+ sendKeyEvents(&mainW, altKey);
+ QCOMPARE(altModifierActivated.size(), 0);
+ QCOMPARE(altKeyActivated.size(), 0);
+ QCOMPARE(altModifierPlusKActivated.size(), 0);
+
+ sendKeyEvents(&mainW, altModifierPlusK);
+ QCOMPARE(altModifierActivated.size(), 0);
+ QCOMPARE(altKeyActivated.size(), 0);
+ QCOMPARE(altModifierPlusKActivated.size(), 1);
+}
+
QTEST_MAIN(tst_QShortcut)
#include "tst_qshortcut.moc"