Reputation: 50338
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?
Upvotes: 1
Views: 1460
Reputation: 14446
Have you tried to modify the size policy of widgets? You can accomplish what you want with this.
Here are all size policies: QSizePolicy — enum QSizePolicy::Policy
Upvotes: 1
Reputation: 1688
If you want the label to fill the space of one line all the time, 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.
Upvotes: 0
Reputation: 350
I think you need to set the stretch factor (setStrechFactor) for the main window you are placing the layout.
Upvotes: 0