我这样叫 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()
当我点击消息框的确定按钮时,它也会关闭我的对话框。怎么避免这个?
答案 0 :(得分:0)
您的代码示例(略微改动以使其运行)适合我:
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_()
您可以在消息框上按“确定”,对话框将不会关闭。您可能正在做其他事情导致关闭对话框。
答案 1 :(得分:0)
像这样使用 QMessageBox :
QMessageBox.critical(self.view, "Error", "System Failure")