View Full Version : Auto-adjusting height of a constant width window

7th July 2010, 02:46
Hello there,
I know that probably this topic has been discussed many times, but I couldn't find a decent answer on the forum for the lack of decent titles policies: I can't look every thread matching my search keywords with a generic title like "qt problem" or "help me I can't resize something".

(Excuse me for this observation. Let's go to the topic.)

I've a window with constant width, a grid layout and 2 labels in it: one at left, one at right.
Right widget is a picture (QLabel), say with height Hp, while left widget is another QLabel with a long text in it.

I can't adjust the widget's height to show all the contents: when it's displayed, it get's Hp as its height. The label with the long text will expand to reach Hp length, but won't expand the widget.

I've tried with size policies, and size constraints, but without success.
I also tried to use heightForWidth(), but doing text.width() it returns 640 (which is even bigger than my window's width). sizeHint won't help either.

A good starting point would be to know how to get the current REAL width of the label (i.e. the width of actually used inside the grid layout), to use heightForWidth(), but I can't understand how to get that value.

How can I force the label to show all its content, given a fixed width, or - better - how to show all the contents of the layout, given it's containing widget's (constant) width?

Thanks very much