[Python] How to change the buttons order in QMessageBox

Discussão em 'Python' iniciado por Stack, Abril 15, 2025.

  1. Stack

    Stack Membro Participativo

    The code creates a QDialog window with a single QPushButton. Clicking the button brings up the QMessageBox window with three buttons. Is there a way to re-arrange the buttons order?

    [​IMG]

    from PyQt4 import QtGui, QtCore
    app = QtGui.QApplication([])

    class Dialog(QtGui.QDialog):
    def __init__(self, parent=None):
    super(Dialog, self).__init__(parent)

    self.resize(300, 100)
    self.setLayout(QtGui.QVBoxLayout())

    button = QtGui.QPushButton('Submit')
    button.clicked.connect(self.onclick)
    self.layout().addWidget(button)

    def onclick(self):
    self.close()
    messagebox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, "Title text", "body text", buttons = QtGui.QMessageBox.Ok | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel, parent=self)
    messagebox.setDefaultButton(QtGui.QMessageBox.No)
    exe = messagebox.exec_()
    print exe

    dialog = Dialog()
    dialog.show()
    app.exec_()

    Continue reading...

Compartilhe esta Página