diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 62c04489152..ded02a756a0 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1745,7 +1745,7 @@ static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, // handles (Yes, No) and (Yes|Default, No) if (defaultButton && !(buttons & defaultButton)) { const int defaultButtons = defaultButton | QMessageBox::Default; - const int otherButtons = static_cast(buttons); + const int otherButtons = buttons.toInt(); const int ret = QMessageBoxPrivate::showOldMessageBox(parent, icon, title, text, otherButtons, defaultButtons, 0); diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 7cd4d01d0ad..0ecb97bff7b 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -282,16 +282,20 @@ void QDialogButtonBoxPrivate::layoutButtons() ++currentLayout; } - QWidget *lastWidget = nullptr; - q->setFocusProxy(nullptr); + QWidgetList layoutWidgets; for (int i = 0; i < buttonLayout->count(); ++i) { - QLayoutItem *item = buttonLayout->itemAt(i); - if (QWidget *widget = item->widget()) { - if (lastWidget) - QWidget::setTabOrder(lastWidget, widget); - else - q->setFocusProxy(widget); - lastWidget = widget; + if (auto *widget = buttonLayout->itemAt(i)->widget()) + layoutWidgets << widget; + } + + q->setFocusProxy(nullptr); + if (!layoutWidgets.isEmpty()) { + QWidget *prev = layoutWidgets.constLast(); + for (QWidget *here : layoutWidgets) { + QWidget::setTabOrder(prev, here); + prev = here; + if (auto *pushButton = qobject_cast(prev); pushButton->isDefault()) + q->setFocusProxy(pushButton); } } diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp index 4d1509469f7..84b7f0dc5fe 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);