How to make the transition from one window to another?
-
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.@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? -
@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?@MAX001
You can do the hide/showing yourself in code, or use aQStackedWidget
or maybe aQWizard
..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. -
@MAX001
You can do the hide/showing yourself in code, or use aQStackedWidget
or maybe aQWizard
..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. -
@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.
-
@MAX001
You might just start from https://doc.qt.io/qt-6/layout.html. It shows layouts and widgets being added dynamically. -
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. -
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.@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 window
Second window
Third window -
@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 window
Second window
Third window@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. -
@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.@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. -
@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.@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 thenshow()
another one to do that in the opposite order. -
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??
-
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??
@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"?