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 t开发者_如何学Cake all the place that it has in a layout, but not more?
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
You can either set a maximumSize or have a look at sizePolicy.
I think you need to set the stretch factor (setStrechFactor) for the main window you are placing the layout.
Maybe you could have a look at the following methods :
- void setScaledContents(bool)
- void setWordWrap(bool on)
I hope it fits your requirements !
Ł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?
精彩评论