How to control placement of "Show Details..." button on PyQt / PySide QMessageBox that uses setDetailedText

StackOverflow https://stackoverflow.com/questions/21319277

Question

When I use setDetailedText on a QMessageBox in PySide, the "Show Details..." button places itself between the Ok and Cancel buttons. Is there a way to control the placement of the button? I like the way it appears in the documentation, but I'd like to see that with different buttons, like Ok and Cancel. I'd like the "Show Details" button to be on the left and the Ok and Cancel to be on the right.

I completely understand that I could achieve this with a completely custom GUI based on QDialog, but I'm interested in whether the MessageBox can do what I want.

Here's my example:

import sys
from PySide import QtCore
from PySide import QtGui


class MyForm(QtGui.QMainWindow):
    def __init__(self, parent=None, args=()):
        super(MyForm, self).__init__(parent)

        self.centralLayout = QtGui.QVBoxLayout()
        self.centralWidget = QtGui.QWidget()
        self.centralWidget.setLayout(self.centralLayout)
        self.setCentralWidget(self.centralWidget)

        self.button = QtGui.QPushButton()
        self.button.setText("Push Me")
        self.button.clicked.connect(self.show_message)
        self.centralLayout.addWidget(self.button)

    def show_message(self):

        msg = QtGui.QMessageBox()
        msg.setWindowTitle("Here's a Title")
        msg.setText("Here's some text")
        msg.setInformativeText("Here's some more text")
        msg.setDetailedText("Here's a whole bunch more detailed text than you might possibly want to know if you're interested.")
        msg.setStandardButtons(QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Ok)
        msg.setDefaultButton(QtGui.QMessageBox.Ok)
        ret = msg.exec_()

        app.exit()

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    MyApp = MyForm()
    MyApp.show()
    sys.exit(app.exec_())

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top