1
votes

I have a following Qt code:

QVBoxLayout* box = new QVBoxLayout;
label = new QLabel(); // will be set later dynamically
box->addWidget (label);

Text in label will be set later. The problem is that when label resizes, it resizes QVBoxLayout, and it resizes other neighboring widgets. I don't want to make a label or layout fixed width. Because I want them to resize with a whole window.

Is it possible to tell a widget to take all the place that it has in a layout, but not more?

5
Can you provide a complete example?baysmith

5 Answers

1
votes

Have you tried to modify the size policy of widgets? You can accomplish what you want with this.

Here are all size policies: http://qt.nokia.com/doc/4.6/qsizepolicy.html#Policy-enum

0
votes

You can either set a maximumSize or have a look at sizePolicy.

0
votes

I think you need to set the stretch factor (setStrechFactor) for the main window you are placing the layout.

0
votes

Maybe you could have a look at the following methods :

- void setScaledContents(bool)
- void setWordWrap(bool on)

I hope it fits your requirements !

0
votes

Łukasz, do I understand you correctly that you want the label to fill the space of one line all the time? If that is so, if the text is just one line, then the solution would simply be:

QVBoxLayout* box = new QVBoxLayout;
label = new QLabel(" "); // The space will create a vertical space in the layout
box->addWidget (label);

The "empty" label will now behave exactly as it will after you set the text.

But I must confess, I'm not sure I truely understand your question. Can you be more specific or maybe provide a screenshot of what you're trying to accomplish?