Yep, the size constraint was the solution:

Qt Code:
  1. //header for class holding tab widget
  2. QGridLayout* dataLayout;
  3. QWidget* page;
  4. QTabWidget* tabs;
  5. QVBoxLayout* mainLayout;
  6.  
  7. //constructor
  8. dataLayout = new QGridLayout();
  9. page = new QWidget(this);
  10. QScrollArea* scrollArea = new QScrollArea(this);
  11. dataLayout->setSizeConstraint(QLayout::SetFixedSize); //important!
  12. page->setLayout(dataLayout);
  13. scrollArea->setWidget(page);
  14. tabs->addTab(scrollArea, tr("Some items"));
  15. mainLayout->addWidget(tabs);
  16. this->setLayout(mainLayout);
  17.  
  18. //test add after construction
  19. for (int n = 0; n < 40; ++n)
  20. {
  21. SomeItem* item = new SomeItem(this);
  22. item->setStuff("whatever");
  23. dataLayout->addWidget(item);
  24. }
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?