Qt (PySide6) - QMdiSubWindow window not calling closeEvent when the X is clicked

12 views Asked by At

I have a sub window inside an MDI. All of the signals work as they should, except for the closeEvent. Additionally, when I close the sub window, it does not get destroyed (it disappears from the MDI, but the object still exists).

What I want is to execute some operations before the window gets destroyed (I click on the X button), which I think I should do in the closeEvent function (?).

I tried setting signals and slots on QtDesigner, using different functions, using example_subwindow.destroyed.connect(), but nothing seems to work.

Here is my code until now

class ExampleWindow(QMainWindow):
    def __init__(self, parent):
        super(ExampleWindow, self).__init__(parent)

        # Get parent
        self.parent_window = parent

        # Load the UI file
        self.ui = self.parent_window.loader.load("Code/UI/example.ui",  None)

        # Sets the window title
        self.ui.setWindowTitle("ExampleTitle")

    def loadWindow(self):
        self.example_subwindow = QMdiSubWindow()
        self.example_subwindow.setWidget(self.ui)
        self.parent_window.ui.mdiArea.addSubWindow(self.example_subwindow)
        self.example_subwindow.show()
    
    def closeEvent(self, event):
        # Do stuff here before the window is closed
        event.accept()
0

There are 0 answers