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 <richard.gustavsen@qt.io>
This commit is contained in:
parent
edbac71691
commit
43f5377fad
@ -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) {
|
||||
|
@ -329,6 +329,12 @@ void tst_QMessageBox::escapeButton()
|
||||
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox2);
|
||||
msgBox2.exec();
|
||||
QVERIFY(msgBox2.clickedButton() == msgBox2.button(QMessageBox::No)); // auto detected (one No button only)
|
||||
|
||||
QMessageBox msgBox3;
|
||||
msgBox3.setDetailedText("Details");
|
||||
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox3);
|
||||
msgBox3.exec();
|
||||
QVERIFY(msgBox3.clickedButton() == msgBox3.button(QMessageBox::Ok)); // auto detected
|
||||
}
|
||||
|
||||
void tst_QMessageBox::statics()
|
||||
|
Loading…
Reference in New Issue
Block a user