From 43f5377fad3f462a033d836fd71a6eb356462c11 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Wed, 18 Jul 2018 17:51:11 +0300 Subject: Make QMessageBox window with the detailed text closable QMessageBox window ignores QCloseEvent if it was created with Ok button and the detailed text was set. But it can be closed if it contains only one button. Make it closable if there are two buttons and one of them is the "Show Details..." button. [ChangeLog][QtWidgets][QMessageBox] A message box with two buttons, one of which is the "Show Details..." button, can be closed by clicking the X button on the window's title bar. Task-number: QTBUG-69526 Change-Id: Iba09e38561eb3898dc2aecfd38d8519d512a71c1 Reviewed-by: Richard Moe Gustavsen --- src/widgets/dialogs/qmessagebox.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/widgets/dialogs/qmessagebox.cpp') diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 52ca88891e..6de952a1d3 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1022,6 +1022,16 @@ void QMessageBoxPrivate::detectEscapeButton() return; } + // If there are two buttons and one of them is the "Show Details..." + // button, then make the other one the escape button + if (buttons.count() == 2 && detailsButton) { + auto idx = buttons.indexOf(detailsButton); + if (idx != -1) { + detectedEscapeButton = buttons.at(1 - idx); + return; + } + } + // if the message box has one RejectRole button, make it the escape button for (auto *button : buttons) { if (buttonBox->buttonRole(button) == QDialogButtonBox::RejectRole) { -- cgit v1.2.3