Important: Please read the Qt Code of Conduct -

[SOLVED] closeEvent question

  • Hi Everyone,

    I have a question with the closeEvent method. If I use self.accept() in the close event I get what I am expecting. If I use event.accept() the window did not execute. Why is event.accept() not working? See below for the example.

    After the second window closes I was expecting the print statement to print. Am I not understanding how exec_() works?

        class Tool1(QtGui.QDialog, ui_tool_1_1.Ui_tool1_1_Dialog):
            """Tool1 dialog"""
            # class Initialization
            def __init__(self, parent=None):
                # python super so script does not need to call the methods by name.
                super(Tool1, self).__init__(parent)
                # Push button to open a new gui.
            def addEvt(self):
                test = AppField(parent=self)
                if test.exec_():
        class AppField(QtGui.QDialog, ui_app_field.Ui_AppFieldDialog):
             Tool 2. 
             # class Initialization
            def __init__(self, parent=None):
                super(AppField, self).__init__(parent)
                # connection to okay button.
            def okay_button(self):
                handles the ok push button.
            def closeEvent(self, event):
                if QtGui.QMessageBox.question(self, "warning", "do you want to close",
                                         QtGui.QMessageBox.Yes|QtGui.QMessageBox.No) == QtGui.QMessageBox.No:

  • Not sure about Phyton, but for c++ i'd use done(int) to exit the dialog.

    So if you have an dialog class myClass and you close it with done(1), myClass.exec() will return 1.

    I'm sure it will be simular for phyton. But i haven't understand the accept and ignore thing, so i cannot explain you why it does not work the way you want to do it

  • My understanding of self.close() got the better of me. self.close() returns self.reject(). That was what I did not understand. self.done(1) would also work, but I think self.accept() is clearer in this case.

    Thank you QT-static-prgm.

Log in to reply