【发布时间】:2018-02-08 19:54:38
【问题描述】:
我想在 QMessageBox 子类中启动一个进程,然后再通过 AcceptRole 返回。我不清楚为什么以下方法不起作用:
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_()
由于 QMessageBox.Ok 的 buttonRole 是 AcceptRole,我希望 accept() 被调用。不是这样吗?
任何见解都将不胜感激。
【问题讨论】:
-
accept() 是一个槽,它不会被自动调用,你必须调用它,所以它永远不会被自动调用。
标签: python pyqt pyqt4 subclass qmessagebox