qt5base-lts/tests/auto/widgets
Tor Arne Vestbø d44413d526 Explicitly focus automatic default button in QDialogButtonBox inside dialog
QDialogButtonBox has logic to automatically resolve a default button,
in case one is not already set via QPushButton directly, or via e.g.
QMessageBox::setDefaultButton().

Unfortunately, this default button can in some cases be overridden by
the first button in the dialog button box. The reason this happens
is that the first button is the focus proxy of the button box, so
when the button box gains focus, it will transfer it to the first
button. And since QPushButtons inside a QDialog have their autoDefault
property set to true by default, this focus transfer will also reset
the default button to the focused button.

This arbitrarily happens for any role that happens to be earlier in
the QDialogButtonBox::ButtonLayout than the AcceptRole, and can be
very confusing for the user, so we try to avoid the situation by
explicitly setting the automatic default button as the focus
widget of the button box, unless one is set already.

This is also what QMessageBox::setDefaultButton() does internally.

The only case we're not covering is when the user sets a push button
as default via QPushButton::setDefault(), but we conservatively
assume that the user then also calls setFocus() on the button.

Pick-to: 6.5 6.6
Change-Id: Ibdac0a51ba9439321d4fd7a1dac1ed695e11d693
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-26 00:14:33 +02:00
..
dialogs Preparations to deprecate QItemDelegate 2023-10-05 21:08:45 +02:00
effects Stabilize tst_QGraphicsEffect::draw() 2023-08-25 09:04:37 +02:00
graphicsview QtWidgets tests: port remaining users away from Q_FOREACH 2023-08-14 23:11:54 +03:00
itemviews Tests/QListView: fix internalDragDropMove test for openSUSE 2023-10-05 19:08:45 +00:00
kernel Use QtGui to match QWindow based shortcuts, even when QApplication is used 2023-10-11 20:32:05 +02:00
styles Reset palette resolve mask in windows vista style 2023-09-05 10:59:00 +02:00
util Remove redundant QPair includes 2023-09-06 17:24:40 +00:00
widgets Explicitly focus automatic default button in QDialogButtonBox inside dialog 2023-10-26 00:14:33 +02:00
CMakeLists.txt tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00