Reputation: 2184
I'm trying to use a QScrollArea
in order to be able to put a lot of widgets on the same window. Unfortunately, the QWidget
containing the QScrollAea
(which is central) is not scaling to the size of the window, which makes it... not like I want... I tried different things but I can't fix it... any idea?
QWidget *central = new QWidget(this);
QScrollArea *scroll = new QScrollArea(this);
QVBoxLayout *vLayout = new QVBoxLayout(central);
this->setCentralWidget(central);
central->setLayout(vLayout);
//vect is not empty
for (elt t : vect)
{
vLayout->addWidget(new TweetDisplay(elt, t));
}
//If I remove those three lines, everything is displayed but of course, I can't scroll.
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scroll->setWidget(central);
scroll->setWidgetResizable(true);
Picture for reference:
Upvotes: 0
Views: 110
Reputation: 462
Instead of setting the central widget to central
you should try using scroll
as your central widget. Thus, the proper line would be:
this->setCentralWidget(scroll);
Remember the scroll area uses central
as the widget it contains already, so setting it as the central widget doesn't actually make sense.
Upvotes: 2