Recommended way to change the user interface at runtime
-
Say, I've created several forms with the Qt Designer, one main window and some widgets. One widget is a little welcome screen that should be displayed at start and as a default screen when no document is open. The application shall create Dungeons & Dragons characters. This welcome screen should be swapped with widgets reponsible for creation and editing of characters, depending what the user wants to. While the welcome screen has no own logic, so it is only a form, the other widgets are actual classes. The problem now is how can I switch between this widgets at runtime.
I tried to use setupUi() on the central widget of the main window, with no success.
Then I created a new layout for the central widget, deleting the old one of course, but while the new widgets appears, the old welcome screen is still there.
So I went on to delete the central widget and recreate a new one. This was actually succesful, but now the menu bar of the main window wouldn't react on input.So far, I need some advice on how to change my user interface at runtime.
-
You could make your central widget a QStackedWidget, and put the "Welcome" screen on the first page, and the "Character Creation" screen on the second page
-
Thank you a lot, I knew, there would be such a possibility, I just didn't find it.
Since I have to put the forms with an actual logic behind it manully into the widget stack, are widgets contructed via new properly deleted?
-
The ownership of the widget is passed on to the QStackedWidget, so it is deleted once the QStackedWidget is deleted.