Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Exclude a window from being checked if it is closed or not?
Forum Updated to NodeBB v4.3 + New Features

Exclude a window from being checked if it is closed or not?

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 1.1k Views 3 Watching
  • 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by
    #1

    Curious question: Is it possible to exclude a QWidget from being checked if it is closed or not when quitting an application?
    I am using a window to show some of the tools and when the main window is closed while this tool window is being shown, the application doesn't quit. I would like the application to quit even if this window is being shown, i.e. this window to be excluded from being counted in if it's open or not to quit the application. There is a quitOnLastWindowClosed property in QGuiApplication, if I could exclude my QWidget window from this being counted in for this property then I guess it can be achieved. Is there any way I could do that?

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • CJhaC CJha

      Curious question: Is it possible to exclude a QWidget from being checked if it is closed or not when quitting an application?
      I am using a window to show some of the tools and when the main window is closed while this tool window is being shown, the application doesn't quit. I would like the application to quit even if this window is being shown, i.e. this window to be excluded from being counted in if it's open or not to quit the application. There is a quitOnLastWindowClosed property in QGuiApplication, if I could exclude my QWidget window from this being counted in for this property then I guess it can be achieved. Is there any way I could do that?

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

      @CJha
      No, else quitOnLastWindowClosed would document how you could exclude a window from being counted, or there would be a quitOnAllButOneWindowClosed property!

      I suggest you write some code to detect when a window is closed and close the tool window yourself if appropriate, or handle the application quit yourself instead of using that behaviour. You could also look at Qt's source code for how it handles that property and use that in your own code.

      Note also its docs state

      If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) is closed.

      I don't know whether your tool window could be set as having a parent, so that it would not count for that check.

      CJhaC 1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        You cannot exclude any widgets. You can handle it yourself

        void MainWindow::closeEvent(QCloseEvent *event)
        {
        myToolWindow->close();
        event->accept();
        } 
        
        1 Reply Last reply
        1
        • CJhaC CJha

          Curious question: Is it possible to exclude a QWidget from being checked if it is closed or not when quitting an application?
          I am using a window to show some of the tools and when the main window is closed while this tool window is being shown, the application doesn't quit. I would like the application to quit even if this window is being shown, i.e. this window to be excluded from being counted in if it's open or not to quit the application. There is a quitOnLastWindowClosed property in QGuiApplication, if I could exclude my QWidget window from this being counted in for this property then I guess it can be achieved. Is there any way I could do that?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @CJha said in Exclude a window from being checked if it is closed or not?:

          Is it possible to exclude a QWidget from being checked if it is closed or not when quitting an application?

          Isn't that the normal behavior for all widgets which have a parent?

          If you make you MainWindow the parent of your toolWidget, it will close with its parent and your app will exit.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          CJhaC 1 Reply Last reply
          0
          • JonBJ JonB

            @CJha
            No, else quitOnLastWindowClosed would document how you could exclude a window from being counted, or there would be a quitOnAllButOneWindowClosed property!

            I suggest you write some code to detect when a window is closed and close the tool window yourself if appropriate, or handle the application quit yourself instead of using that behaviour. You could also look at Qt's source code for how it handles that property and use that in your own code.

            Note also its docs state

            If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) is closed.

            I don't know whether your tool window could be set as having a parent, so that it would not count for that check.

            CJhaC Offline
            CJhaC Offline
            CJha
            wrote on last edited by
            #5

            @JonB Thanks! I will see if I can achieve the same result by any other means.

            1 Reply Last reply
            0
            • Pl45m4P Pl45m4

              @CJha said in Exclude a window from being checked if it is closed or not?:

              Is it possible to exclude a QWidget from being checked if it is closed or not when quitting an application?

              Isn't that the normal behavior for all widgets which have a parent?

              If you make you MainWindow the parent of your toolWidget, it will close with its parent and your app will exit.

              CJhaC Offline
              CJhaC Offline
              CJha
              wrote on last edited by
              #6

              @Pl45m4 My tool widget is an independent window, I cannot assign MainWIndow as its parent.

              Pl45m4P 1 Reply Last reply
              0
              • CJhaC CJha

                @Pl45m4 My tool widget is an independent window, I cannot assign MainWIndow as its parent.

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #7

                @CJha said in Exclude a window from being checked if it is closed or not?:

                I cannot assign MainWIndow as its parent.

                You cannot or you don't want to (due to your app design structure)?
                Because I believe you can :) Even a QMainWindow can have a parent


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                CJhaC 1 Reply Last reply
                0
                • Pl45m4P Pl45m4

                  @CJha said in Exclude a window from being checked if it is closed or not?:

                  I cannot assign MainWIndow as its parent.

                  You cannot or you don't want to (due to your app design structure)?
                  Because I believe you can :) Even a QMainWindow can have a parent

                  CJhaC Offline
                  CJhaC Offline
                  CJha
                  wrote on last edited by
                  #8

                  @Pl45m4 Yes, I don't want to because of my app structure. This tool window is supposed to be completely independent of any other part of the app. MainWindow is not aware that this tool window exists, and the tool window is not aware that MainWindow exists.

                  Pl45m4P mrjjM 2 Replies Last reply
                  0
                  • CJhaC CJha

                    @Pl45m4 Yes, I don't want to because of my app structure. This tool window is supposed to be completely independent of any other part of the app. MainWindow is not aware that this tool window exists, and the tool window is not aware that MainWindow exists.

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by
                    #9

                    @CJha said in Exclude a window from being checked if it is closed or not?:

                    MainWindow is not aware that this tool window exists

                    So @mrjj 's solution won't work either?!

                    Tricky. Then it might not be possible ;-)


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    CJhaC 1 Reply Last reply
                    0
                    • CJhaC CJha

                      @Pl45m4 Yes, I don't want to because of my app structure. This tool window is supposed to be completely independent of any other part of the app. MainWindow is not aware that this tool window exists, and the tool window is not aware that MainWindow exists.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @CJha
                      Hi
                      But there is not that many options.
                      Either the tool window is closed by being owned by a parent or
                      you close it manually when you want to.
                      If you don't want a pointer in MainWindow to the tool, you could use signal / slot
                      so MainWindow will emit ImClosing and others can react to that.

                      CJhaC 1 Reply Last reply
                      0
                      • Pl45m4P Pl45m4

                        @CJha said in Exclude a window from being checked if it is closed or not?:

                        MainWindow is not aware that this tool window exists

                        So @mrjj 's solution won't work either?!

                        Tricky. Then it might not be possible ;-)

                        CJhaC Offline
                        CJhaC Offline
                        CJha
                        wrote on last edited by
                        #11

                        @Pl45m4 Yes, that's right. That's why I posted this question :)

                        1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @CJha
                          Hi
                          But there is not that many options.
                          Either the tool window is closed by being owned by a parent or
                          you close it manually when you want to.
                          If you don't want a pointer in MainWindow to the tool, you could use signal / slot
                          so MainWindow will emit ImClosing and others can react to that.

                          CJhaC Offline
                          CJhaC Offline
                          CJha
                          wrote on last edited by
                          #12

                          @mrjj Thanks! that's a solution. But, I am put a lot of constraints on the tool window. It is created just after QApplication object is created and before the QMainWindow object is created. I would like it to be completely independent, kind of "make it and forget it" fashion, and so I am not connecting any signals to my tool window except for signals from QApplication (and therefore from QGuiApplication and QCoreApplication). I am trying right now to see if I can detect inside my tool window if it's the only window, by hooking up to the QGuiApplication::focusWindowChanged signal, if it is the only window then I will close it.

                          mrjjM 1 Reply Last reply
                          0
                          • CJhaC CJha

                            @mrjj Thanks! that's a solution. But, I am put a lot of constraints on the tool window. It is created just after QApplication object is created and before the QMainWindow object is created. I would like it to be completely independent, kind of "make it and forget it" fashion, and so I am not connecting any signals to my tool window except for signals from QApplication (and therefore from QGuiApplication and QCoreApplication). I am trying right now to see if I can detect inside my tool window if it's the only window, by hooking up to the QGuiApplication::focusWindowChanged signal, if it is the only window then I will close it.

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by mrjj
                            #13

                            @CJha
                            Hi
                            Ok. no signals then :)

                            Try use
                            QWidgetList QApplication::topLevelWidgets

                            and see if ToolWindow is listed.

                            I imagine then when MainWin is close the size of list is 1

                            focusWindowChanged could also work. if its not fired if the user clicks on some other window.

                            CJhaC 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @CJha
                              Hi
                              Ok. no signals then :)

                              Try use
                              QWidgetList QApplication::topLevelWidgets

                              and see if ToolWindow is listed.

                              I imagine then when MainWin is close the size of list is 1

                              focusWindowChanged could also work. if its not fired if the user clicks on some other window.

                              CJhaC Offline
                              CJhaC Offline
                              CJha
                              wrote on last edited by
                              #14

                              @mrjj Thanks, I need a signal to know when to check QApplication::topLevelWidgets, I think I will create an event filter and apply it to QApplication and this way I can hook on to any close event that is generated in the application. I just tried with focusWindowChanged signal, it works as long my tool window is not minimized.

                              1 Reply Last reply
                              2

                              • Login

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