Nominate our 2022 Qt Champions!

Hide pages in Stacked Widget

  • Hello, is there a way to hide some pages dynamically in a Stacked Widget?

  • Lifetime Qt Champion

    The page is just a widget so it can be hidden as such BUT
    it still exits in its list and as far as i know, it wont skip over them
    when u set setCurrentIndex(int index)
    So if u need various pages at different times, i think you have to use
    void QStackedWidget::removeWidget(QWidget *widget)
    to truly hide it.

    Is this some kind of Wizard ?

  • say you have 3 pages (a,b,c), you hide the second (b) what should happen if you call setCurrentIndex(1)?

  • Moderators

    You have full control over which page is shown when you call setCurrentIndex(). So if you have, for example, some "Next" button which activates next page, you can implement "hiding" like this:

    void on_next_clicked()
      int i = stack->currentIndex();
      if (i == 5) {
        // Oh! I want to skip page with index 5

Log in to reply