summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-10-10 09:32:32 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-10-11 17:12:54 +0000
commitd8eac9a71a4f951971d7cf3e20a72dba90800ac7 (patch)
treeb17af6e553a3e2b9de0565505cfb071cdc197cf6 /tests
parent45af046be7a2251284c923e52d42d7b6c7790026 (diff)
QDialog: respect WA_ShowWithoutActivating
QDialog overrides setVisible to set focus on the default push button, or (if there is no such button), make the first autoDefault push button the default button. QDialog also explicitly sends a FocusIn event to the focus widget in the dialog. All this should not be done if the dialog does not become active after getting shown, which will be prevented if the WA_ShowWithoutActivating attribute is set. Add a test case. Fixes: QTBUG-8857 Change-Id: If47021a4721a280ba45e95b43d0424cdacd9b4ea Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit 44b9aec8d900af77281f2e9209d54e946ee2fe76) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp
index 03b84c0fda..c7e0c269d3 100644
--- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp
+++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp
@@ -70,6 +70,8 @@ private slots:
void showMinimized();
void showFullScreen();
void showAsTool();
+ void showWithoutActivating_data();
+ void showWithoutActivating();
void toolDialogPosition();
void deleteMainDefault();
void deleteInExec();
@@ -323,6 +325,33 @@ void tst_QDialog::showAsTool()
}
}
+void tst_QDialog::showWithoutActivating_data()
+{
+ QTest::addColumn<bool>("showWithoutActivating");
+ QTest::addColumn<int>("focusInCount");
+
+ QTest::addRow("showWithoutActivating") << true << 0;
+ QTest::addRow("showWithActivating") << false << 1;
+}
+
+void tst_QDialog::showWithoutActivating()
+{
+ QFETCH(bool, showWithoutActivating);
+ QFETCH(int, focusInCount);
+
+ struct Dialog : public QDialog
+ {
+ int focusInCount = 0;
+ protected:
+ void focusInEvent(QFocusEvent *) override { ++focusInCount; }
+ } dialog;
+ dialog.setAttribute(Qt::WA_ShowWithoutActivating, showWithoutActivating);
+
+ dialog.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dialog));
+ QCOMPARE(dialog.focusInCount, focusInCount);
+}
+
// Verify that pos() returns the same before and after show()
// for a dialog with the Tool window type.
void tst_QDialog::toolDialogPosition()