[PyQt] QMessagebox.exec_() documentation

Phil Thompson phil at riverbankcomputing.com
Sun May 9 17:56:13 BST 2010


On Sun, 9 May 2010 18:32:33 +0200, Wolfgang Rohdewald
<wolfgang at rohdewald.de> wrote:
> 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.

It should be.

> exec_() is only used in
> examples but not explicitly defined so I would expect it to behave like
the
> inherited QDialog.exec_()

You should expect it to behave like QMessageBox::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

As the Qt docs say, use clickedButton().

Phil


More information about the PyQt mailing list