I found that there is something like detectedEscapeButton in QMessageBox and setting detailed description causes situation where QMessageBox can't determine detectedEscapeButton so this:
{
if (!d->detectedEscapeButton) {
e->ignore();
return;
}
d->clickedButton = d->detectedEscapeButton;
setResult(d->execReturnCode(d->detectedEscapeButton));
}
void QMessageBox::closeEvent(QCloseEvent *e)
{
Q_D(QMessageBox);
if (!d->detectedEscapeButton) {
e->ignore();
return;
}
QDialog::closeEvent(e);
d->clickedButton = d->detectedEscapeButton;
setResult(d->execReturnCode(d->detectedEscapeButton));
}
To copy to clipboard, switch view to plain text mode
means that with detectedEscapeButton set to 0 close event is always ignored.
In detail: escape button detection is performed on show event. If there is no explicitly set escape button (setEscapeButton) then it is detected which means that QMessageBox search for any button with RejectRole or NoRole or if there is only one button then this one becomes escape button. Adding detailed text adds second button so there is no proper rule to set detectedEscapeButton.
I found the solution and it is adding yout own button with RejectRole or NoRole but remember that you will get diffrent return code from exec() in this code:
msg.setWindowTitle("Error");
msg.setText("Sambungan ke database gagal!");
msg.setDetailedText("Cape Deh...");
qDebug("%d", msg.exec()); // here now 0 is returned, with default created OK button it was 1024 (QMessageBox::Ok)
QMessageBox msg;
msg.setIcon(QMessageBox::Critical);
msg.setWindowTitle("Error");
msg.setText("Sambungan ke database gagal!");
msg.setDetailedText("Cape Deh...");
msg.addButton("OK", QMessageBox::RejectRole);
qDebug("%d", msg.exec()); // here now 0 is returned, with default created OK button it was 1024 (QMessageBox::Ok)
To copy to clipboard, switch view to plain text mode
Bookmarks