I noticed an interesting thing - if I add a detailed text to QMessageBox (which adds "Show Details..." button) then executing it will show the system frame's close (X) button disabled and hence marking this window as non-closable (right click on frame -> Close disabled).
Here is some sample code:
QMessageBox box(QMessageBox::Critical, title, text, QMessageBox::Ok);
box.setDetailedText(detailedText); // comment this line to get close button enabled
box.exec();
I didn't even find a way to manually do this in Qt. Any ideas?
Thanks
I was having the same problem with Python 2.7 and PySide.
In this example, the red close button works as expected:
Adding detailed text disables the close button:
The answer marked as the solution does not solve this problem. As you can see in this example, the close button remains disabled:
The answer is to set the standard buttons and ALSO set the escape button:
This restores the desired close button behavior.
You need to unset the Qt::WindowCloseButtonHint widget flag. Like this:
You may unset this flag Qt::WindowSystemMenuHint either.
http://qt-project.org/doc/qt-4.8/qt.html#WindowType-enum
I came across this recently on Qt 4.8 Linux. I found that whether or not the X was disabled depended on the ButtonRole I used on the call to QMessageBox::addButton(). The X was disabled when all roles were ActionRole - which is really supposed to be for buttons that affect the dialog, but do not accept or reject it. What the buttons did in my case is more accurately described as AcceptRole or RejectRole. When I changed the roles to have one RejectRole and the rest AcceptRole, the X started working. It looks as though QMessageBox was reluctant to accept a close when none of the buttons had roles that mapped to close.