This should be easy and I found topics similar to this but I'm still stuck, so I'll
ask in a new thread: How do I get the contents of a tab in a QTabWidget to scroll?

I create a scroll area, set a layout to it and then insert it to a tab
widget. Later, I add widgets to that layout. However, scroll bars never
appear. Instead, the widgets get partially stacked on top of each other.
What am I doing wrong? I'm trying to avoid having to create a custom
widget for each and every tab and then using scrollarea->setWidget() but
is that really the problem?

Qt Code:
  1. //in header for base class:
  2. protected:
  3. QVBoxLayout* vlayout;
  4.  
  5. //in header for this class:
  6. private:
  7. QTabWidget* tabs;
  8.  
  9. //in constructor for this class:
  10. tabs = new QTabWidget(this);
  11. grid = new QGridLayout();
  12. grid->setAlignment(Qt::AlignLeft | Qt::AlignTop);
  13. QScrollArea* scrollarea = new QScrollArea(this);
  14. scrollarea->setLayout(grid);
  15. tabs->addTab(scrollarea, tr("Look, items!"));
  16. vlayout->addWidget(tabs);
  17.  
  18. //items get added some time after construction:
  19. SomeItem* item = new SomeItem(this); //not derived from base class, does have a layout
  20. item->setStuff("stuff");
  21. grid ->addWidget(item);
To copy to clipboard, switch view to plain text mode