View Full Version : Question to state Machine and *.ui

12th June 2014, 15:31
Hi All,

I want to realize a GUI, where the screen layout changes, when I click on a button. Like having a welcome screen with one Button and by clicking it, the screen changes to a completely different look. Therefore I implemented a state machine, that shall load the different "screens". And I made some different screens with the Designer (so I have different *.ui-Files).
The problem is, that the Designer makes everytime a QWidget, and when the state machine starts a new screen, the old one is only closed by it. I think, I want the state machine to change only the Layout of one main QWidget.
I found the Quiloader, but I am not sure. if that is the solution to my problem.

Does anybody has a suggestion for me, what to do best?


12th June 2014, 16:22
QStackedWidget might be just what you need.

13th June 2014, 07:22

wouldn't it be better to use QStackedLayout? Then I would only have the mainWindow and would change the Layouts, when I would need a new screenView. Or is the QStackedWidget better?

13th June 2014, 08:02
Hi, QStackedWidget is "a convenience class built on top of QStackedLayout" so they are very similar in functionality.


13th June 2014, 09:25

ok the hint with QStackedWidget was genious. This was exactly, what I needed.

Thank you very much.

13th June 2014, 10:01
Indeed, QStackedLayout works too, but I mentioned QStackedWidget because you can create and populate it directly in Qt Designer. By contrast, writing the code manually allows you to choose either solution; in that case I suppose I would use QStackedLayout because I expect it to be the (slightly) lighter alternative.

14th June 2014, 15:12
Would you generally prefer creating the views with the designer or manually?

17th June 2014, 10:23
I only do widgets manually if something is not possible in designer, e.g. create widgets dynamically depending on state in the application.

For a stacked widget it would depend on how much UI related logic each page has, i.e. if a page is complex I would do it as its own widget and then add it to the stacked widget (either through promotion or in code).