From 2cd1f9f03dfa3ade16c86a7a44e843f7698e5ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 29 Sep 2023 13:58:58 +0200 Subject: [PATCH] Simplify tst_QShortcut There's no need for the manual sendKeyEvent, as QTest already has the ability to send synthetic clicks, and we don't need a colored window to test shortcut activation. Change-Id: I8409888664e2316bec4ea64f21dbb8b6915091f4 Reviewed-by: Friedemann Kleint (cherry picked from commit 8606f33641a0a2fb9926ebb604a7fc5894e5fc39) Reviewed-by: Qt Cherry-pick Bot --- .../gui/kernel/qshortcut/tst_qshortcut.cpp | 33 ++----------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp index 8a1b2888a27..9f1d70e5459 100644 --- a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp +++ b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp @@ -4,53 +4,24 @@ #include #include #include -#include -#include -#include #include class tst_QShortcut : public QObject { Q_OBJECT -public: private slots: void trigger(); }; -class ColoredWindow : public QRasterWindow { -public: - ColoredWindow(QColor c) : m_color(c) {} - -protected: - void paintEvent(QPaintEvent *event) override; - -private: - const QColor m_color; -}; - -void ColoredWindow::paintEvent(QPaintEvent *) -{ - QPainter p(this); - p.fillRect(QRect(QPoint(), size()), m_color); -} - -static void sendKey(QWindow *target, Qt::Key k, char c, Qt::KeyboardModifiers modifiers) -{ - QTest::sendKeyEvent(QTest::Press, target, k, c, modifiers); - QTest::sendKeyEvent(QTest::Release, target, k, c, modifiers); -} - void tst_QShortcut::trigger() { - ColoredWindow w(Qt::yellow); - w.setTitle(QTest::currentTestFunction()); - w.resize(QGuiApplication::primaryScreen()->size() / 4); + QWindow w; new QShortcut(Qt::CTRL | Qt::Key_Q, &w, SLOT(close())); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); QTRY_VERIFY(QGuiApplication::applicationState() == Qt::ApplicationActive); - sendKey(&w, Qt::Key_Q, 'q', Qt::ControlModifier); + QTest::sendKeyEvent(QTest::Click, &w, Qt::Key_Q, 'q', Qt::ControlModifier); QTRY_VERIFY(!w.isVisible()); }