Hello, and thanks for reading.

Consider a class Foo which is something like
Qt Code:
  1. Foo :: Foo (QWidget * parent) : QWidget(parent) {
  2. my_layout = new QVBoxLayout (this);
  3. setLayout (my_layout);
  4. }
  5.  
  6. void Foo :: bar () {
  7. my_layout -> addWidget (new SomeWidget());
  8. }
To copy to clipboard, switch view to plain text mode 

If Foo inherits from QWidget then it behaves as expected: the height increases to accomodate the contens every time bar() is called.

If this grows to big I need a vertical scrollbar. However, if Foo inherits from QScrollArea then it does not resize to fit the new contents; rather, the new widgets are squashed together. Ironically, this makes the scrollbar redundant.

How to I make Foo stack the child widgets correctly as in the non-scrolling version?

Thanks