summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-10-10 09:32:32 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-10-11 15:48:33 +0200
commit44b9aec8d900af77281f2e9209d54e946ee2fe76 (patch)
tree115aee4aa5191646da90624b1353312190add90d /tests/auto/widgets/dialogs
parent3fc58a5ed837bc5135198a05255ca7ac72ced69e (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 Pick-to: 6.2 Change-Id: If47021a4721a280ba45e95b43d0424cdacd9b4ea Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/widgets/dialogs')
-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 e585835c3d..f61e585fda 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()