我像这样调用QMessageBox():
class Main(QDialog):
def __init__(self):
self.view = QUiLoader().load("app.ui", self)
self.view.show()
self.functionA()
....
functionA():
try:
....
except Exception:
QMessageBox.critical(self, "Error", "System Failure")
def main():
app = QApplication(sys.argv)
a = Main()
sys.exit(app.exec_())
if __name__ == "__main__"
main()
当我单击消息框的"确定"按钮时,它也会关闭我的对话框。如何避免这种情况?
您的代码示例(稍作更改以使其运行)对我有用:
from PySide.QtGui import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.show()
self.functionA()
def functionA(self):
try:
raise Exception()
except Exception:
QMessageBox.critical(self, "Error", "System Failure")
app = QApplication([])
a = Main()
app.exec_()
您可以在消息框上按 OK,对话框将不会关闭。您可能还在执行其他导致对话框关闭的操作。
像
这样使用 QMessageBox:
QMessageBox.critical(self.view, "Error", "System Failure")