summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qshortcut
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-10-02 12:40:56 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-10-04 20:36:53 +0200
commitc8599f1626caa6502ee64a91015a434eedba6909 (patch)
treefb5de74f0887755578052e380e612b7468f720d6 /tests/auto/gui/kernel/qshortcut
parentcf13e4c84c44b6f66f651035b3c3d012718b82dc (diff)
Add QShortcut test for Qt::ApplicationShortcut
A Qt::ApplicationShortcut shortcut is not tied to a specific window. We do however document that the shortcut "is active when one of the applications windows are active", which seems like a strange limitation, but for now we honor it in our test as well by making another window active. Change-Id: I235230ff69df29ee43d356d3efaeedb20071faf3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel/qshortcut')
-rw-r--r--tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp
index 9f1d70e545..a0ffaa5854 100644
--- a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp
@@ -5,16 +5,38 @@
#include <QtGui/qguiapplication.h>
#include <QtGui/qshortcut.h>
#include <QtGui/qwindow.h>
+#include <QtTest/qsignalspy.h>
class tst_QShortcut : public QObject
{
Q_OBJECT
private slots:
- void trigger();
+ void applicationShortcut();
+ void windowShortcut();
};
-void tst_QShortcut::trigger()
+void tst_QShortcut::applicationShortcut()
+{
+ auto *shortcut = new QShortcut(Qt::CTRL | Qt::Key_A, this);
+ shortcut->setContext(Qt::ApplicationShortcut);
+ QSignalSpy activatedSpy(shortcut, &QShortcut::activated);
+
+ // Need a window to send key event to, even if the shortcut is application
+ // global. The documentation for Qt::ApplicationShortcut also says that
+ // the shortcut "is active when one of the applications windows are active",
+ // but this is only honored for Qt Widgets, not for Qt Gui. For now we
+ // activate the window just in case.
+ QWindow window;
+ window.show();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+ QTRY_COMPARE(QGuiApplication::applicationState(), Qt::ApplicationActive);
+ QTest::sendKeyEvent(QTest::Shortcut, &window, Qt::Key_A, 'a', Qt::ControlModifier);
+
+ QVERIFY(activatedSpy.size() > 0);
+}
+
+void tst_QShortcut::windowShortcut()
{
QWindow w;
new QShortcut(Qt::CTRL | Qt::Key_Q, &w, SLOT(close()));