summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-11-30 17:46:56 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-12-03 12:53:02 +0100
commitec0e11201e7c19166b2d078d53eb9fcad9e98ac5 (patch)
treeb53a2693807eb587d48514f13893d3b7d52d5c61 /tests
parentf783bc4a3bbbee4ac34d3bf65a64c66e40ec292f (diff)
QPA: Set focus reason when window activation changes focus
QApplication hides the fact that the reason is never set by several QPA plugins, but Quick items don't receive the correct reason on Windows, Android, the offscreen plugin, and other platforms. Add relevant scenario to the QFocusEvent test case, and fix the plugins to always set the focus reason when handling window activation changes. Exclude the minimal plugin from the test, it seems largely unmaintained anyway. Task-number: QTBUG-75862 Change-Id: I5404a225b387fc9a3851b6968d0777c687127ed1 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit c034ad03ac6896b9fba8a72e01a1b7ec34cf0cd5) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/other/qfocusevent/tst_qfocusevent.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp
index cd00f4cc9c..92ab429d4a 100644
--- a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp
+++ b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp
@@ -369,6 +369,42 @@ void tst_QFocusEvent::checkReason_ActiveWindow()
QVERIFY( childFocusWidgetOne->hasFocus() );
QVERIFY( childFocusWidgetOne->focusInEventRecieved );
QCOMPARE( childFocusWidgetOne->focusInEventReason, (int)Qt::ActiveWindowFocusReason);
+
+ const bool windowActivationReasonFail =
+ QGuiApplication::platformName().toLower() == "minimal";
+
+ struct Window : public QWindow
+ {
+ Qt::FocusReason lastReason = Qt::NoFocusReason;
+ protected:
+ void focusInEvent(QFocusEvent *event) override
+ {
+ lastReason = event->reason();
+ }
+ void focusOutEvent(QFocusEvent *event) override
+ {
+ lastReason = event->reason();
+ }
+ };
+
+ Window window;
+ window.show();
+ window.requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+
+ if (windowActivationReasonFail)
+ QEXPECT_FAIL("", "Platform doesn't set window activation reason for QWindow", Continue);
+ QCOMPARE(window.lastReason, Qt::ActiveWindowFocusReason);
+ window.lastReason = Qt::NoFocusReason;
+
+ Window window2;
+ window2.show();
+ window2.requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(&window2));
+
+ if (windowActivationReasonFail)
+ QEXPECT_FAIL("", "Platform doesn't set window activation reason for QWindow", Continue);
+ QCOMPARE(window.lastReason, Qt::ActiveWindowFocusReason);
}