diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index dcddc693c83..3350a926f0c 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -2565,8 +2565,10 @@ void QMessageBox::setDetailedText(const QString &text) d->detailsText->hide(); } if (!d->detailsButton) { + const bool autoAddOkButton = d->autoAddOkButton; // QTBUG-39334, addButton() clears the flag. d->detailsButton = new DetailButton(this); addButton(d->detailsButton, QMessageBox::ActionRole); + d->autoAddOkButton = autoAddOkButton; } d->detailsText->setText(text); } diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp index 0425db30986..f9abd50a154 100644 --- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp @@ -593,6 +593,11 @@ void tst_QMessageBox::detailsText() QString text("This is the details text."); box.setDetailedText(text); QCOMPARE(box.detailedText(), text); + box.show(); + QTest::qWaitForWindowExposed(&box); + // QTBUG-39334, the box should now have the default "Ok" button as well as + // the "Show Details.." button. + QCOMPARE(box.findChildren().size(), 2); } void tst_QMessageBox::detailsButtonText()