You would need to add to valuesLayout
only QScrollArea
object, let's say scrollArea
.
You would need to create QWidget
, which would be in scrollArea
, let's say scrollWidget
and set QVBoxLayout
for scrollWidget
, let's say scrollLayout
, now you can add your widgets to scrollLayout
and they would appear inside your QScrollArea
, so the code should look something like this (it's a bit tricky and cofusing, but will be easy in time):
//The header file:
QVBoxLayout *valuesLayout;
QVBoxLayout *scrollLayout;
QScrollArea *scrollArea;
QWidget *scrollWidget;
//The corresponding .cpp file
valuesLayout = new QVBoxLayout(); // creating layout for valuesPage
scrollArea=new QScrollArea(valuesPage); // creates scrollarea, and set valuesPage as it's parent
scrollWidget =new QWidget(scrollArea); // creates scrollwidget, your scrollArea as parent
scrollLayout = new QVBoxLayout(scrollWidget); // creating layout in scrollWidget
for (int j=0; j<100; j++)
{
scrollLayout->addWidget(new PaIndicator(0, "This is a test", 0)); // adding your widgets to scrolllayout
}
scrollArea->setWidget(scrollWidget); // sets scrollArea around scrollWidget
valuesPage->setLayout(valuesLayout); //valuesPage is my QStackedWidget page
valuesLayout->addWidget(scrollArea ); // adding scrollwidget to your mainlayout