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

QStackedWidget and QT Creator



  • So, trying to play with QStackedWidget and have read the docs for it. If I'm using Creator to modify my app layout I can drag a QStackedWidget onto my layout and it default gives you two stacked widgets. In the docs it states I need to add a QComboBox or a QListWidget. Does this still need to be done? Or is this just to give the user the capability to "switch pages"?

    So, if the user never "chooses" a page, I can change it in the program using setCurrentIndex()?

    And, if so, is it simply done something like this?
    stackedWidget.setCurrentIndex(1);



  • @MichRX7 said in QStackedWidget and QT Creator:

    Does this still need to be done?

    "No" to that one. "Yes" to all your other questions. Which is about what @dheerendra has replied.

    stackedWidget.setCurrentIndex(1) or stackedWidget.setCurrentWidget(one_of_the_widgets_set_via_stackedWidget_addWidget) if you have the widget-page you want shown available to you rather than its index in the QStackedWidget, either one does the job.


  • Qt Champions 2017

    I'm not really sure what is the question here. What is the help you require. Nevertheless QStackWidget name indicates you can add any number & any type of widgets QStackWidget. Show any widget in the stack by setting the current Index.

    You can look at the doc. They have given an example. In the docs they are using the combobox to select the appropriate widget. You can try. This does not mean that you need to always use the combobox to select the widget in stackwidget. Selection of widget can based on some condition.



  • @MichRX7 said in QStackedWidget and QT Creator:

    Does this still need to be done?

    "No" to that one. "Yes" to all your other questions. Which is about what @dheerendra has replied.

    stackedWidget.setCurrentIndex(1) or stackedWidget.setCurrentWidget(one_of_the_widgets_set_via_stackedWidget_addWidget) if you have the widget-page you want shown available to you rather than its index in the QStackedWidget, either one does the job.


Log in to reply