[Solved] Restrain Height of QHBoxLayout
-
Hello,
I've looked into the doc and played around with QHBoxLayout, but i can't seem to be able to restrain its size (especially it height).
I have a layout with labels, and icons, i want it to be 25px high (not less, not more). I've tried to use 'setGeometry()' passing in a QRect and 'setHeight(25)', and then using setSizeConstraint(3). But no matter what i choose, the layout seems to take on a height of about 40 to 50. The layout's geometry().height() however shows '0' no matter what i do...
I'm a bit confused now, could you help me?Thanks.
Benjamin -
Try this:
Set its layoutsizeconstraint to fixedsize.
Also the labels, icons you use in the layout should have size policy fixed.(at least one of them)
-
Thanks. It's exactly what i did:
@self.label1 = QtGui.QLabel("hello", self)
self.label1.setFixedHeight(24)self.hbox = QtGui.QHBoxLayout()
self.hbox.addStretch(0)
self.hbox.setSizeConstraint(QtGui.QLayout.SetFixedSize)
self.hbox.addWidget(self.label1)self.setLayout(self.hbox)@
And if i query the geometry:
label heightis: 24
hbox sizehint PyQt4.QtCore.QSize(72, 24)
hbox margins:
top: 0;
bottom: 0
hbox size constraint: 3
hbox geometry:
height: 0;
width: 0;
x pos: 0;
y pos: 0;
top: 0;
bottom: -1Despite this, the height is not 24, but rather app. 40 to 50 px high.
-
it think you forgot to set
label->setMinimumSize(QSize(50, 24));
or something like that. -
Apparently the problem was due to the margins of the QHBoxLayout which i had to set with setContentsMargins(0, 0, 0, 0).
Thanks.
B.