gpt4 book ai didi

python - 如何子类化 QMessageBox 并在关闭之前运行操作

转载 作者:行者123 更新时间:2023-12-01 02:11:06 25 4
gpt4 key购买 nike

我想在 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() 。难道不是这样吗?

如有任何见解,我们将不胜感激。

最佳答案

你的想法是对的。你只需要重新实现虚拟done()插槽,而不是虚拟 accept() 插槽:

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)

结果将为StandardButton所单击按钮的值(即上例中的 QMessageBox.OkQMessageBox.Cancel)。

关于python - 如何子类化 QMessageBox 并在关闭之前运行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48693735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com