I was having the same problem with Python 2.7 and PySide.
In this example, the red close button works as expected:
from PySide import QtGui, QtCore
import sys
app = QtGui.QApplication(sys.argv)
message_box = QtGui.QMessageBox()
message_box.setWindowTitle("Close Test")
message_box.setText("Testing whether or not the red X is enabled.")
ret = message_box.exec_()
Adding detailed text disables the close button:
from PySide import QtGui, QtCore
import sys
app = QtGui.QApplication(sys.argv)
message_box = QtGui.QMessageBox()
message_box.setWindowTitle("Close Test")
message_box.setText("Testing whether or not the red X is enabled.")
message_box.setDetailedText("These details disable the close button for some reason.")
ret = message_box.exec_()
The answer marked as the solution does not solve this problem. As you can see in this example, the close button remains disabled:
from PySide import QtGui, QtCore
import sys
app = QtGui.QApplication(sys.argv)
message_box = QtGui.QMessageBox()
message_box.setWindowTitle("Close Test")
message_box.setText("Testing whether or not the red X is enabled.")
message_box.setDetailedText("These details disable the close button for some reason.")
message_box.setWindowFlags(message_box.windowFlags() & ~QtCore.Qt.WindowCloseButtonHint)
ret = message_box.exec_()
The answer is to set the standard buttons and ALSO set the escape button:
from PySide import QtGui, QtCore
import sys
app = QtGui.QApplication(sys.argv)
message_box = QtGui.QMessageBox()
message_box.setWindowTitle("Close Test")
message_box.setText("Testing whether or not the red X is enabled.")
message_box.setDetailedText("These details disable the close button for some reason.")
message_box.setStandardButtons(QtGui.QMessageBox.Ok)
message_box.setDefaultButton(QtGui.QMessageBox.Ok)
message_box.setEscapeButton(QtGui.QMessageBox.Ok)
ret = message_box.exec_()
This restores the desired close button behavior.