PDA

View Full Version : Inconsistent behaviour of QVBoxLayout



spraff
26th November 2008, 17:54
Hi there. I have a QWidget which contains a QScrollArea which contains a MyList which has a QVBoxLayout. MyList has a slot

void MyList :: add_new () {
MyWidget * w = new MyWidget (this);
layout () -> addWidget (w);
}

I can call add_new repeatedly from the MyList constructor and the behaviour is as expected: a new widget is added to the end of the list and eventually a scroll bar appears as the MyList widget grows.

If I call add_new later as the result of a user action, the height of the MyList widget is fixed and everything is squashed to accomadate the new MyWidget.

Is this a bug or do I need to change some setting?

wysota
26th November 2008, 18:05
If I understand you correctly then yes, this is expected. Your top level widget gets some dimensions while it is being shown and then if you add more widgets, it is not resized anymore - the layout applied to it manages its current space. As the space doesn't change and the requirements for it grow, each widget gets less space. If you want to override this behaviour, apply a constraint to the top level widget's layout (Fixed probably being the one you want).

spraff
26th November 2008, 18:59
Can you please explain how a "Fixed" layout is supposed to allow growth? I don't understand the inner logic.

(I'm having minor issues elsewhere in my app where widgets ought to push out their parents, so knowing what the mechanism is would help.)

I wonder if this is somehow connected to the fact that sizePolicy sever seems to do anything :eek:

wysota
26th November 2008, 19:36
It says the dialog is always to be of the size equal to the sizeHint of its layout's widgets. If you add a new widget, the "total sizeHint" will grow, hence the dialog will grow with it. Note that I'm not talking about the "sizePolicy" of the dialog but of the size constraint of its layout.