Search code examples
qtpysideqmessagebox

Don’t close Dialog on pressing OK button of QMessageBox


I have called QMessageBox() like this:

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()

When i click OK button of Message box it also closes my Dialog. How to avoid this ?


Solution

  • Use QMessageBox like this:

    QMessageBox.critical(self.view, "Error", "System Failure")