diff options
author | Axel Spoerl <axel.spoerl@qt.io> | 2023-11-23 13:05:58 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-12-20 16:16:53 +0000 |
commit | d71b73c145a35a84547918abe4b0916a7ced6a1e (patch) | |
tree | f8122ffc3c00cdb73a955658fcae8bf866a25e3b /src/widgets/dialogs | |
parent | fd710fbba3d24f6192625f586eea57309630f8ac (diff) |
Pass correct default button in QMessageBox::showNewMessageBox()
showNewMessageBox() shows an "old" message box, if a default button
argument was passed and the buttons argument doesn't contain a default
button. It passed the int value of defaultButton to showOldMessageBox,
where it was interpreted as a normal button.
The StandardButton::Default flag was not set on the default button.
This relied on the QDialogButtonBox owned by QMessageBox to show the
expected default button by co-incidence. As this was not always the
case, tst_QMessageBox::staticSourceCompat() even tested wrong expected
results.
=> Add the Default flag to the default button, before passing it as an
int value.
=> As a drive-by,
- replace c-style casting with static casting.
- add braces to multi-line if clause.
Task-number: QTBUG-118489
Pick-to: 6.7 6.6 6.5
Change-Id: I9cf93c8f93d6ab80e7be5ab25e56bc59d3d6209c
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index e0edfe4e03..f55113b3ca 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1729,11 +1729,14 @@ static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, { // necessary for source compatibility with Qt 4.0 and 4.1 // handles (Yes, No) and (Yes|Default, No) - if (defaultButton && !(buttons & defaultButton)) - return (QMessageBox::StandardButton) - QMessageBoxPrivate::showOldMessageBox(parent, icon, title, - text, int(buttons), - int(defaultButton), 0); + if (defaultButton && !(buttons & defaultButton)) { + const int defaultButtons = defaultButton | QMessageBox::Default; + const int otherButtons = static_cast<int>(buttons); + const int ret = QMessageBoxPrivate::showOldMessageBox(parent, icon, title, + text, otherButtons, + defaultButtons, 0); + return static_cast<QMessageBox::StandardButton>(ret); + } QMessageBox msgBox(icon, title, text, QMessageBox::NoButton, parent); QDialogButtonBox *buttonBox = msgBox.findChild<QDialogButtonBox*>(); |