Nominate our 2022 Qt Champions!

How to set scroll bar to a stacked widget?

  • Hi All,I m new to qt and have so far used the designer mode to brings items in place.I have a stacked widget with several items.

    I want to add a scroll bar(both horizontal and vertical ) to my stackedwidget.

    Things I have done:

    1. In the designer,I have the below but its showing the scrollbars ,but not getting scrolled.


    2.I had only StackedWidget in my GUI and added the scrollarea and QWidget programmatically.

         QWidget * mainWidget = new QWidget(ui->stackedWidget);
         QVBoxLayout * vLayout = new QVBoxLayout(mainWidget);
         QScrollArea * scrollArea = new QScrollArea(mainWidget);

    But now,the scrollbar is not getting shown.Any help woould be really helpful.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Something is not clear, do you want your stacked widget to be in a QScrollArea programmatically ? Or have the scroll area to be inside the QStackedWidget ?

Log in to reply