Daniel
Daniel

Reputation: 2726

How to fix the size of a qt groupbox and align it on the top?

Newbie here. I have a dock widget, and in it I created three groupbox, and using VBoxLayout for these three groupboxes. But the problem is when the window is maximized, the three groupboxes fill the whole dock widget and there a lots of large spacing inside of the items in the groupboxes. How can I keep the size of groupbox fixed and also as in the whole dock widget panel, keep them all aligned on the top?

What's the trick? Thanks

Upvotes: 3

Views: 2907

Answers (2)

Youssef Bouhjira
Youssef Bouhjira

Reputation: 1631

You have to add a QSpcerItem but not directly :

Normally, you don't need to use this class directly. Qt's built-in layout managers provide the following functions for manipulating empty space in layouts: ...

from Qt documentation : http://doc.qt.digia.com/qt/qspaceritem.html#details

you have to use :

myLayout->addStretch()

Upvotes: 2

user1006989
user1006989

Reputation:

Use a QSpacerItem. For a vertical spacer use:

 QSpacerItem ( width, height, QSizePolicy::Minimum, QtGui.QSizePolicy::Expanding )

And for an horizontal:

 QSpacerItem ( width, height, QtGui.QSizePolicy::Expanding, QSizePolicy::Minimum )

Upvotes: 0

Related Questions