Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMainWindow swap Central Widget or QStackedWidget



  • I have the following Situation:

    A Widget of type A which is like a Dialog. Which can only get accepted.

    A Widget of type B which runs the main application

    A Widget of type C which reports the Outcome of the main widget. It is also like a Dialog with the choice to start a new B or quit the program.

    So my program flow is :

    Display A.
    A gets accepted.
    Display B
    B-> finnishes.
    Dsiplay C (show the result of B)

    Have the option to start again a new B (Some aspects of B are random so it has to get created new everytime we switch back).

    I was wondering how to organize the flow of the programm the best?

    • Putting them in a QMainWindow and change centralWidget ?
      -> I tryed this approach it seems to work but A and C don't follow the size rules since they are based on QDialog. So in Short evrytime I switch centralWidget the QMainWindow jumps to annother place and resizes. Even with setFixedSize

    • Or use QStackedWidget and get the old B and C out at the time to replace them with new ones?

    • Annother option im not aware off.

    I hope you can push me in the right direction here.


  • Lifetime Qt Champion

    Hi,

    Why do you need to put them out of the stacked widget ?
    Implement them so that you can refresh/reset them so you only have one instance of each and be done with it.


Log in to reply