prabhakaran
prabhakaran

Reputation: 5274

Qt - How to control the widget sizes in QLayout

I am trying to put some spinboxes,line edits in a layout. But the size extends more than the neccesity. Below is the figure alt text

Here I am adding a QScrollArea widget,and a QVBoxLayout into a QHBoxLayout. Then I am adding the line edits,spin boxes into the QVBoxLayout. But I want to reduce the width as 2/10 of the total width. Can anybody help me in this?

Upvotes: 2

Views: 15887

Answers (4)

Sebastian Negraszus
Sebastian Negraszus

Reputation: 12215

In my opinion, working with stretch factors is not the right solution, here. It's a bit "hackish". Stretch factors are useful e.g. when you have two widgets that both use as much space as possible, but not at a 50:50 rate.

Here, as I see it, you have two widgets (or groups of widgets), where one should only use as much space as it really needs and the other one should take the rest. That is what size policies are for. Set the horizontal policy of the left one to Expanding (or MinimumExpanding if you want to prevent scroll bars) and the right one to Preferred.

Upvotes: 7

Andrew
Andrew

Reputation: 24846

Take a look at QSizePolicy. It may be usefull.

Upvotes: 0

prabhakaran
prabhakaran

Reputation: 5274

It's easy. It can be done by giving the stretching factor. That means you have to initiate the value when you use the functions

addWidget(widget,stretchfactor);
       or
addLayout(layout,stretchfactor);

Upvotes: 4

canardman
canardman

Reputation: 3263

I think you should try with void setSizeConstraint ( SizeConstraint ) and minimumSize() inherited methods.

Read the doc

Upvotes: 0

Related Questions