PDA

View Full Version : Layout, widgets and resize questions



Carlsberg
26th June 2009, 07:57
Hello,

I have 2 little questions, maybe silly ones:

I have a widget to which I attach a layout. Then I add lots of buttons & co to the layout.

First question:

How can I make the parent widget resize depending on the widgets I add or remove from the layout? I managed to make it grow, but removing widgets from the layout will not make the parent widget shrink. In the end I did it by resizing it myself, but I wonder if there isn't a smarter idea

Second question:

After adding the widgets on the layout, when will the geometry of the widget be updated so I can get the correct height by using widget.height()? After all kind of trials I managed to do that only after calling widget.setVisible(true). It is possible to get the height without that call?

Thank you :o

zgulser
26th June 2009, 11:08
Hi,

First of all I wonder why you want to remove your widget? I mean if you want your regarding widget to shrink itself via a widget removal, doesn't it break down the layout of your other widgets, windows, frames etc.

Carlsberg
26th June 2009, 13:49
No, it doesn't. I have a scroll area and the widget we're talking about is the widget set to the scroll area. Something like this:



QWidget* theWidget = new QWidget();
QVBoxLayou* theLayout = new QVBoxLayout(theWidget);
theLayout->addWidget(...)
theLayout->addWidget(...)
theLayout->addWidget(...)

QScrollArea* sc = new QScrollArea();
sc->setWidget(theWidget);