[PyQt] QMessagebox.exec_() documentation

Wolfgang Rohdewald wolfgang at rohdewald.de
Sun May 9 17:32:33 BST 2010


the doc at http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qmessagebox.html#exec
says that the exec_() slot returns the StandardButtons value of 
the button that was clicked.

The C++ doc says if user defined buttons are used, an opaque value is returned.
This is not mentioned in the PyQt4 doc. exec_() is only used in
examples but not explicitly defined so I would expect it to behave like the
inherited QDialog.exec_()

In the class below, QMessageBox.exec_() returns 0 for for the button with
the YesRole and 1 for the button with the NoRole. Why is that so? Could
this be an index into the button list? It certainly is not a
QMessageBox.ButtonRole value.

Using pyqt 4.7.2 on kubuntu 10.04

class SwapDialog(QMessageBox):
    def __init__(self, swappers):
        QMessageBox.__init__(self)
        self.setWindowTitle(m18n("Swap Seats") + ' - Kajongg')
        self.setText("By the rules, %s and %s should now exchange their seats. " % \
            (swappers[0].name, swappers[1].name))
        self.yesAnswer = QPushButton("&Exchange")
        self.addButton(self.yesAnswer, QMessageBox.YesRole)
        self.noAnswer = QPushButton("&Keep seat")
        self.addButton(self.noAnswer, QMessageBox.NoRole)

    def exec_(self):
        QMessageBox.exec_(self)
        # ignore strange exec_ return value
        return self.clickedButton() == self.yesAnswer


-- 
Wolfgang


More information about the PyQt mailing list