(Python + Pyqt5) How to not let main application be closed without closing "daughters" windows open.?

Asked

Viewed 375 times

1

I have my main application with menus (Menubar) where calls the function that creates and opens another window "daughter".

My problem is in the part where I can close my main application without before closing that child window.

How to lock system closure without first having closed all daughter windows open?

Code of the main application.

class ViewMainWindow(QMainWindow):
    def __init__(self, controller_main):
        super(ViewMainWindow, self).__init__()
        self.ui_main_window = Ui_main_MainWindow()
        self.ui_main_window.setupUi(self)

        self._controller_main = controller_main
        self._view_scd_window = ViewSCDWindow()

        self.ui_main_window.action_SCD.triggered.connect(self._view_scd_window.create_scd_window)

Code of the child window:

class ViewSCDWindow(QMainWindow):
    def __init__(self):
        super(ViewSCDWindow, self).__init__()
        self.ui_scd_window = Ui_scd_form()
        self.ui_scd_window.setupUi(self)

    def create_scd_window(self):
        self.show()

All windows are inherited from the template created by QT Design.

  • this is exactly what you need https://stackoverflow.com/questions/18256459/qdialog-prevent-closing-in-python-and-pyqt. I don’t have enough expertise in pyqt to risk a response.

  • Thanks for trying to help @Filipe Gonçalves but unfortunately that’s not exactly what I need. Basically I need that when capturing the closeEvent() "Accept" event to be scanned to see if you have an active window and if so, do not let the system close without closing the windows, or close all together.

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.