[Qt-interest] adapt the size of a QLabel inside a QVBoxLayout

Girish Ramakrishnan girish at forwardbias.in
Wed Feb 25 11:42:45 CET 2009


Markus Franke wrote:
> Dear Qt Developers/Users,
> 
> I have a QLabel inside a QVBoxLayout. The text of the QLabel is dynamic,
> word wrapping is enabled for the QLabel and I am calling
> QWidget::adjustSize() on the QLabel.

You don't need to call adjustSize(). When the text of a label changes,
it invalidates its size hint by calling updateGeometry(). The layout
picks up this notification and lays out the widgets.

The behavior you want is the default behaviour of a wrapping QLabel.

The reason you might be seeing the problem might be that the layout has
a fixed size contraint or some top level layout has similar contraint,
which prevents the layout from growing.

Maybe you can send some simple code that doesn't work?

Girish



More information about the Qt-interest-old mailing list