Yep, the size constraint was the solution:
//header for class holding tab widget
//constructor
dataLayout
->setSizeConstraint
(QLayout::SetFixedSize);
//important!page->setLayout(dataLayout);
scrollArea->setWidget(page);
tabs->addTab(scrollArea, tr("Some items"));
mainLayout->addWidget(tabs);
this->setLayout(mainLayout);
//test add after construction
for (int n = 0; n < 40; ++n)
{
SomeItem* item = new SomeItem(this);
item->setStuff("whatever");
dataLayout->addWidget(item);
}
//header for class holding tab widget
QGridLayout* dataLayout;
QWidget* page;
QTabWidget* tabs;
QVBoxLayout* mainLayout;
//constructor
dataLayout = new QGridLayout();
page = new QWidget(this);
QScrollArea* scrollArea = new QScrollArea(this);
dataLayout->setSizeConstraint(QLayout::SetFixedSize); //important!
page->setLayout(dataLayout);
scrollArea->setWidget(page);
tabs->addTab(scrollArea, tr("Some items"));
mainLayout->addWidget(tabs);
this->setLayout(mainLayout);
//test add after construction
for (int n = 0; n < 40; ++n)
{
SomeItem* item = new SomeItem(this);
item->setStuff("whatever");
dataLayout->addWidget(item);
}
To copy to clipboard, switch view to plain text mode
- Without setSizeConstraint(QLayout::SetFixedSize) the items will not even be displayed
- Adding items in the constructor does not work (tried after every phase)
- Not using a "page" QWidget and calling scrollArea->setLayout(dataLayout)
does not work. Subclassing an actual custom Page widget from QWidget, however, is not
required.
I wonder what use does QScrollArea::setLayout() even have?
Bookmarks