Issue
I would like to launch a process within a QMessageBox subclass before it returns via the AcceptRole. It's not clear to me why the following does not work:
class Question(QtGui.QMessageBox):
def __init__(self, text):
QtGui.QMessageBox.__init__(self, QtGui.QMessageBox.Question,
"title", text, buttons=QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
self.text = text
def accept(self):
# run opertation
print self.text
QtGui.QMessageBox.accept(self)
dial = Question("text")
dial.exec_()
Since the buttonRole for QMessageBox.Ok is AcceptRole, I would expect accept()
to be called. Is this not the case?
Any insight would be appreciated.
Solution
You have the right idea. You just need to reimplement the virtual done() slot, rather than the virtual accept()
slot:
class Question(QtGui.QMessageBox):
def __init__(self, text):
QtGui.QMessageBox.__init__(
self, QtGui.QMessageBox.Question, "title", text,
buttons=QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
self.text = text
def done(self, result):
print self.text
QtGui.QMessageBox.done(self, result)
The result
will be StandardButton value of the button that was clicked (i.e. QMessageBox.Ok
or QMessageBox.Cancel
, in the above example).
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.