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 to make the transition from one window to another?

How to make the transition from one window to another?

Scheduled Pinned Locked Moved Unsolved Qt for Python
14 Posts 6 Posters 1.8k 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
    MAX001
    wrote on last edited by
    #1

    I saw someone use QStackedWidget, but it will keep all windows in memory (((. I also saw the implementation with .close and .show Window, but when recording video on the window, when I click on the button, the application seems to restart constantly and the recording stops because there is no such window anymore. How can this normally be implemented?054dc0e5-9d64-425e-bae0-ae89e2b29512-image.png

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      By default Qt application exits main event loop (and thus exits the app) when last top window is closed. See QGuiApplication::quitOnLastWindowClosed property.

      So if you want to prevent the app from closing either make sure there's at least one window still visible (e.g. by reversing the order of show/close) or set that application attribute to false before you switch. In that case make sure to set it back to true afterwards or manually call QCoreApplication::quit when you're ready to exit your app, or it will never exit on its own.

      Btw. just so you know - closing a widget does not release its resources, just hides the window. To delete it you need to explicitly call deleteLater on it or set the WA_DeleteOnClose attribute so that it is deleted when closed automatically.

      M 1 Reply Last reply
      5
      • Chris KawaC Chris Kawa

        By default Qt application exits main event loop (and thus exits the app) when last top window is closed. See QGuiApplication::quitOnLastWindowClosed property.

        So if you want to prevent the app from closing either make sure there's at least one window still visible (e.g. by reversing the order of show/close) or set that application attribute to false before you switch. In that case make sure to set it back to true afterwards or manually call QCoreApplication::quit when you're ready to exit your app, or it will never exit on its own.

        Btw. just so you know - closing a widget does not release its resources, just hides the window. To delete it you need to explicitly call deleteLater on it or set the WA_DeleteOnClose attribute so that it is deleted when closed automatically.

        M Offline
        M Offline
        MAX001
        wrote on last edited by
        #3

        @Chris-Kawa That is, so it will be possible to implement a button transition from one window to another without using QStackedWidget? And is it possible to somehow reduce the number of ui files if a new ui file is created when creating a new window and if I have 100 transitions through the application with different content, then there will be 100 ui files?

        JonBJ 1 Reply Last reply
        0
        • M MAX001

          @Chris-Kawa That is, so it will be possible to implement a button transition from one window to another without using QStackedWidget? And is it possible to somehow reduce the number of ui files if a new ui file is created when creating a new window and if I have 100 transitions through the application with different content, then there will be 100 ui files?

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

          @MAX001
          You can do the hide/showing yourself in code, or use a QStackedWidget or maybe a QWizard.

          .ui files are only created at design-time using the Designer. You can create 100 different ones if you want, or you can do the work in code and create them dynamically at runtime without any .ui files. Depends whether you need to "visually design" each one. Or you can create "template" ones visually at design time and alter them at runtime for different purposes.

          M 1 Reply Last reply
          1
          • JonBJ JonB

            @MAX001
            You can do the hide/showing yourself in code, or use a QStackedWidget or maybe a QWizard.

            .ui files are only created at design-time using the Designer. You can create 100 different ones if you want, or you can do the work in code and create them dynamically at runtime without any .ui files. Depends whether you need to "visually design" each one. Or you can create "template" ones visually at design time and alter them at runtime for different purposes.

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

            @JonB Sorry, maybe is some good links and examples how to do that dynamically?

            So maybe I can implement many windows and transitions between them.

            JonBJ 1 Reply Last reply
            0
            • M MAX001

              @JonB Sorry, maybe is some good links and examples how to do that dynamically?

              So maybe I can implement many windows and transitions between them.

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

              @MAX001
              You might just start from https://doc.qt.io/qt-6/layout.html. It shows layouts and widgets being added dynamically.

              M 1 Reply Last reply
              0
              • JonBJ JonB

                @MAX001
                You might just start from https://doc.qt.io/qt-6/layout.html. It shows layouts and widgets being added dynamically.

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

                @JonB But what if I create a window and in it each new window will be a frame (Function). Run the application with the first frame and then run the next frames as needed. And also make a function that will remove all widgets from the previous window?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  Can you explain the logic of your application ?
                  Also, since you have memory considerations in mind, are you planning to create that many widgets that it will eat through all resources of your device ? If so, then there's likely an architectural issue with your design.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  M 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Hi,

                    Can you explain the logic of your application ?
                    Also, since you have memory considerations in mind, are you planning to create that many widgets that it will eat through all resources of your device ? If so, then there's likely an architectural issue with your design.

                    M Offline
                    M Offline
                    MAX001
                    wrote on last edited by MAX001
                    #9

                    @SGaist As a project, I want to implement an application that will start from the main window. On the main window there will be a button on which I will go to a window with three pictures and three buttons I will do in the Grid Layout at the bottom there will be a button back to the main screen for each of those three buttons I will go to the third window in which there will be three buttons at the top
                    1 - recognition of objects in the picture
                    2 - recognition of objects by video
                    3 - recognition via webcam
                    and by clicking on each of these buttons, the result of recognition by image, video and webcam will be displayed at the bottom.

                    This is what I created earlier, but the problem is with the buttons, the application is interrupted when switching to another window and restarts, destroying the old window, but I would like it to update the content in one window.
                    First windowc66ca8ff-48b8-4d27-ba95-f17f1bfc4de2-image.png
                    Second window81c55bce-678d-4180-82ec-4d1069183eda-image.png
                    Third window50f5efb9-ee9b-4e48-929f-805e45065c84-image.png

                    JonBJ 1 Reply Last reply
                    0
                    • M MAX001

                      @SGaist As a project, I want to implement an application that will start from the main window. On the main window there will be a button on which I will go to a window with three pictures and three buttons I will do in the Grid Layout at the bottom there will be a button back to the main screen for each of those three buttons I will go to the third window in which there will be three buttons at the top
                      1 - recognition of objects in the picture
                      2 - recognition of objects by video
                      3 - recognition via webcam
                      and by clicking on each of these buttons, the result of recognition by image, video and webcam will be displayed at the bottom.

                      This is what I created earlier, but the problem is with the buttons, the application is interrupted when switching to another window and restarts, destroying the old window, but I would like it to update the content in one window.
                      First windowc66ca8ff-48b8-4d27-ba95-f17f1bfc4de2-image.png
                      Second window81c55bce-678d-4180-82ec-4d1069183eda-image.png
                      Third window50f5efb9-ee9b-4e48-929f-805e45065c84-image.png

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @MAX001
                      How does this add up to the "then there will be 100 ui files?" you mentioned earlier?

                      the application is interrupted when switching to another window and restarts, destroying the old window, but I would like it to update the content in one window.

                      Then you are doing something wrong, but we don't know what.

                      Given that you have buttons which move the user "forward and backward" through screens in the application, I suggested earlier you might look at QWizard Class, or you could do whatever similar with QStackedWidget. Given that you have "Start" and "Go back" and "transitions" between one page at a time that the user interacts with, I don't see why you want to display all these windows displayed separately.

                      M 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @MAX001
                        How does this add up to the "then there will be 100 ui files?" you mentioned earlier?

                        the application is interrupted when switching to another window and restarts, destroying the old window, but I would like it to update the content in one window.

                        Then you are doing something wrong, but we don't know what.

                        Given that you have buttons which move the user "forward and backward" through screens in the application, I suggested earlier you might look at QWizard Class, or you could do whatever similar with QStackedWidget. Given that you have "Start" and "Go back" and "transitions" between one page at a time that the user interacts with, I don't see why you want to display all these windows displayed separately.

                        M Offline
                        M Offline
                        MAX001
                        wrote on last edited by MAX001
                        #11

                        @JonB
                        As I mentioned earlier, I want to make such an application.
                        @MAX001 Post

                        @SGaist As a project, I want to implement an application that will start from the main window. On the main window there will be a button on which I will go to a window with three pictures and three buttons I will do in the Grid Layout at the bottom there will be a button back to the main screen for each of those three buttons I will go to the third window in which there will be three buttons at the top
                        1 - recognition of objects in the picture
                        2 - recognition of objects by video
                        3 - recognition via webcam
                        and by clicking on each of these buttons, the result of recognition by image, video and webcam will be displayed at the bottom.

                        This is what I created earlier, but the problem is with the buttons, the application is interrupted when switching to another window and restarts, destroying the old window, but I would like it to update the content in one window.

                        I wouldn't want to use QStackedWidget because it keeps all the widgets in memory and if my application grows I won't consume too much memory.
                        Something I would like to do is to use frames that will replace each other in the same window. At least that's the concept.

                        JonBJ 1 Reply Last reply
                        0
                        • M MAX001

                          @JonB
                          As I mentioned earlier, I want to make such an application.
                          @MAX001 Post

                          @SGaist As a project, I want to implement an application that will start from the main window. On the main window there will be a button on which I will go to a window with three pictures and three buttons I will do in the Grid Layout at the bottom there will be a button back to the main screen for each of those three buttons I will go to the third window in which there will be three buttons at the top
                          1 - recognition of objects in the picture
                          2 - recognition of objects by video
                          3 - recognition via webcam
                          and by clicking on each of these buttons, the result of recognition by image, video and webcam will be displayed at the bottom.

                          This is what I created earlier, but the problem is with the buttons, the application is interrupted when switching to another window and restarts, destroying the old window, but I would like it to update the content in one window.

                          I wouldn't want to use QStackedWidget because it keeps all the widgets in memory and if my application grows I won't consume too much memory.
                          Something I would like to do is to use frames that will replace each other in the same window. At least that's the concept.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #12

                          @MAX001 said in How to make the transition from one window to another?:

                          I wouldn't want to use QStackedWidget because it keeps all the widgets in memory and if my application grows I won't consume too much memory.

                          I would not assume your way is any better for memory consumption. Your code does not necessarily destroy the widgets/windows you create anyway. Besides nothing to stop you destroying and recreating windows you use in a stacked widget as you go if that's what you want to do. And I still have not seen evidence of "100 ui files".

                          So long as you stick with your way be aware that if you close the last visible windows before you show a new one your application is likely to close with the default Qt behaviour of quitOnLastWindowClosed : bool. If your application is "quitting" when you move from one window to the next you might think of changing that or reversing the way you close() one window and then show() another one to do that in the opposite order.

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            Faraz_Ahmad
                            wrote on last edited by
                            #13

                            Well, I read all this conversation and came to a conclusion that, switching between frames is indeed a good idea, However I prefer to use QStackedWidget. Because it helps us meet all scenarios for navigational purpose.

                            I just have a question to both of you quys what if I want to make the transitions in small part of the window rather than the whole window. How can I do that??

                            jsulmJ 1 Reply Last reply
                            0
                            • F Faraz_Ahmad

                              Well, I read all this conversation and came to a conclusion that, switching between frames is indeed a good idea, However I prefer to use QStackedWidget. Because it helps us meet all scenarios for navigational purpose.

                              I just have a question to both of you quys what if I want to make the transitions in small part of the window rather than the whole window. How can I do that??

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @Faraz_Ahmad said in How to make the transition from one window to another?:

                              if I want to make the transitions in small part of the window rather than the whole window

                              What do you mean by that? What is this "small part"?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              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