summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2023-11-20 10:26:12 +0100
committerAxel Spoerl <axel.spoerl@qt.io>2023-12-20 17:16:53 +0100
commitd4f38a363251fcb5cdfb24d7a1aceb7b630f7e8f (patch)
treeb5289d196c743d7582f3ba5500a61fff803131da /tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
parentd71b73c145a35a84547918abe4b0916a7ced6a1e (diff)
QDialogButtonBox: Fix focus chain and default button assignment
QDialogButtonBox::layoutButtons() rebuilds the focus chain based on the button layout. It relied on the fact that the last button in the layout would point back to the first button. That is not the case, if - a focus frame gets inserted in the chain, and - the default button is not at the layout's first (=left) position. In that case, the chain stops at the button left of the default button. The default button can not be reached by tabbing forward. Back-tabbing still worked. By not "closing" the focus chain, the focus proxy was set to the first button found in the layout. That is wrong, whenever the default button is not at the first layout position. When the box got focus for the first time, pressing "Enter" could lead to a non-default button being triggered. A Yes/No message box would have No as its default button. On Linux, it would pop up with "No" being highlighted, but "Yes" having focus. Pressing Enter would trigger Yes, instead of No. tst_QMessageBox::staticSourceCompat() heuristically defines the button expected to be triggered by Enter. On Linux/KDE, it would pass, when the wrong button was fired. => Always "close" the focus chain, by linking the last and first buttons. => Make the default button the button box's focus proxy. => Change tst_QMessageBox::staticSourceCompat() to always expect No being fired by Enter in a Yes/No box. [ChangeLog][QtWidgets][QDialogButtonBox] Default button becomes focus proxy of a QDialogButtonBox. This ensures that Enter triggers the default button, instead of the first button in the layout. Fixes: QTBUG-118489 Pick-to: 6.7 6.6 6.5 Change-Id: Ic626d3d0fe7ba8b924c21734332e98532f11c80e Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp')
-rw-r--r--tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp9
1 files changed, 1 insertions, 8 deletions
diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
index 4d1509469f..84b7f0dc5f 100644
--- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
+++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
@@ -481,14 +481,7 @@ QT_WARNING_DISABLE_DEPRECATED
ExecCloseHelper closeHelper;
closeHelper.start(Qt::Key_Enter);
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No);
- int expectedButton = int(QMessageBox::Yes);
- if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
- const int dialogButtonBoxLayout = theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt();
- if (dialogButtonBoxLayout == QDialogButtonBox::MacLayout
- || dialogButtonBoxLayout == QDialogButtonBox::GnomeLayout)
- expectedButton = int(QMessageBox::No);
- }
- COMPARE(ret, expectedButton);
+ COMPARE(ret, QMessageBox::No);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);