Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How do I get a signal to close the main window?
Forum Updated to NodeBB v4.3 + New Features

How do I get a signal to close the main window?

Scheduled Pinned Locked Moved Unsolved Qt for Python
8 Posts 2 Posters 8.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    Hi!
    How do I get a signal to close the main window?
    If I open another window but close the main window, I don't get these closing signals:

    self.ui.destroyed.connect(lambda : print(6666666))
    self.destroyed.connect(lambda: print(777777777777))
    

    My class:

    class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = uic.loadUi("mainWindow.ui")
    

    And not work event :

     def closeEvent(self, event):
            print("closeEvent")
    
    JonBJ 1 Reply Last reply
    0
    • M Mikeeeeee

      Hi!
      How do I get a signal to close the main window?
      If I open another window but close the main window, I don't get these closing signals:

      self.ui.destroyed.connect(lambda : print(6666666))
      self.destroyed.connect(lambda: print(777777777777))
      

      My class:

      class MainWindow(QMainWindow):
      def __init__(self):
          super(MainWindow, self).__init__()
          self.ui = uic.loadUi("mainWindow.ui")
      

      And not work event :

       def closeEvent(self, event):
              print("closeEvent")
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @Mikeeeeee
      What are you looking for an answer?

      If I open another window but close the main window, I don't get these closing signals:

      Qt has a default behaviour of quitting application when the last window is closed, like if you just have a main window. If you have another window open that won't get fired.

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #3

        How do I know that the self.ui window is closed?

        JonBJ 1 Reply Last reply
        0
        • M Mikeeeeee

          How do I know that the self.ui window is closed?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @Mikeeeeee
          If you want to know when a QWidget is closed, you can sub-class and override the closeEvent(). Closing in itself does not emit any signal, so that is the way to recognise it.

          M 1 Reply Last reply
          4
          • JonBJ JonB

            @Mikeeeeee
            If you want to know when a QWidget is closed, you can sub-class and override the closeEvent(). Closing in itself does not emit any signal, so that is the way to recognise it.

            M Offline
            M Offline
            Mikeeeeee
            wrote on last edited by
            #5

            @JonB But how do I create a subclass for self.ui?

            JonBJ 1 Reply Last reply
            0
            • M Mikeeeeee

              @JonB But how do I create a subclass for self.ui?

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @Mikeeeeee
              You don't, it's not a QWidget! self.ui itself does not close or send signals etc. It owns widgets which do.

              M 1 Reply Last reply
              2
              • JonBJ JonB

                @Mikeeeeee
                You don't, it's not a QWidget! self.ui itself does not close or send signals etc. It owns widgets which do.

                M Offline
                M Offline
                Mikeeeeee
                wrote on last edited by
                #7

                @JonB So how do I know that "mainWindow. ui" is closed?

                JonBJ 1 Reply Last reply
                0
                • M Mikeeeeee

                  @JonB So how do I know that "mainWindow. ui" is closed?

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Mikeeeeee
                  What class is ui.mainWindow? It needs to be your class derived from QMainWindow. Then you go override that class's closeEvent().

                  I see https://stackoverflow.com/questions/22460003/pyqts-qmainwindow-closeevent-is-never-called is for PyQt4, but look at the solution, I imagine it will be similar for PyQt5/PySide2.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved