View Full Version : Growing the contents of a scroll area.

2nd July 2009, 16:07
Hello, and thanks for reading.

Consider a class Foo which is something like

Foo :: Foo (QWidget * parent) : QWidget(parent) {
my_layout = new QVBoxLayout (this);
setLayout (my_layout);

void Foo :: bar () {
my_layout -> addWidget (new SomeWidget());

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?


2nd July 2009, 16:20
Use QScrollArea::setWidgetResizable().