QBoxLayout¶
The
QBoxLayout
class lines up child widgets horizontally or vertically. More…
Inherited by: QHBoxLayout, QVBoxLayout
Synopsis¶
Functions¶
def
addLayout
(layout[, stretch=0])def
addSpacerItem
(spacerItem)def
addSpacing
(size)def
addStretch
([stretch=0])def
addStrut
(arg__1)def
addWidget
(arg__1[, stretch=0[, alignment=Qt.Alignment()]])def
direction
()def
insertItem
(index, arg__2)def
insertLayout
(index, layout[, stretch=0])def
insertSpacerItem
(index, spacerItem)def
insertSpacing
(index, size)def
insertStretch
(index[, stretch=0])def
insertWidget
(index, widget[, stretch=0[, alignment=Qt.Alignment()]])def
setDirection
(arg__1)def
setStretch
(index, stretch)def
setStretchFactor
(l, stretch)def
setStretchFactor
(w, stretch)def
stretch
(index)
Detailed Description¶
QBoxLayout
takes the space it gets (from its parent layout or from theparentWidget()
), divides it up into a row of boxes, and makes each managed widget fill one box.If the
QBoxLayout
‘s orientation isHorizontal
the boxes are placed in a row, with suitable sizes. Each widget (or other box) will get at least its minimum size and at most its maximum size. Any excess space is shared according to the stretch factors (more about that below).If the
QBoxLayout
‘s orientation isVertical
, the boxes are placed in a column, again with suitable sizes.The easiest way to create a
QBoxLayout
is to use one of the convenience classes, e.g.QHBoxLayout
(forHorizontal
boxes) orQVBoxLayout
(forVertical
boxes). You can also use theQBoxLayout
constructor directly, specifying its direction asLeftToRight
,RightToLeft
,TopToBottom
, orBottomToTop
.If the
QBoxLayout
is not the top-level layout (i.e. it is not managing all of the widget’s area and children), you must add it to its parent layout before you can do anything with it. The normal way to add a layout is by calling parentLayout->addLayout()
.Once you have done this, you can add boxes to the
QBoxLayout
using one of four functions:
addWidget()
to add a widget to theQBoxLayout
and set the widget’s stretch factor. (The stretch factor is along the row of boxes.)
addSpacing()
to create an empty box; this is one of the functions you use to create nice and spacious dialogs. See below for ways to set margins.
addStretch()
to create an empty, stretchable box.
addLayout()
to add a box containing anotherQLayout
to the row and set that layout’s stretch factor.Use
insertWidget()
,insertSpacing()
,insertStretch()
orinsertLayout()
to insert a box at a specified position in the layout.
QBoxLayout
also includes two margin widths:
setContentsMargins()
sets the width of the outer border on each side of the widget. This is the width of the reserved space along each of theQBoxLayout
‘s four sides.
setSpacing()
sets the width between neighboring boxes. (You can useaddSpacing()
to get more space at a particular spot.)The margin default is provided by the style. The default margin most Qt styles specify is 9 for child widgets and 11 for windows. The spacing defaults to the same as the margin width for a top-level layout, or to the same as the parent layout.
To remove a widget from a layout, call
removeWidget()
. Callinghide()
on a widget also effectively removes the widget from the layout untilshow()
is called.You will almost always want to use
QVBoxLayout
andQHBoxLayout
rather thanQBoxLayout
because of their convenient constructors.See also
- class PySide2.QtWidgets.QBoxLayout(arg__1[, parent=None])¶
- param parent:
- param arg__1:
Constructs a new
QBoxLayout
with directiondir
and parent widgetparent
.The layout is set directly as the top-level layout for
parent
. There can be only one top-level layout for a widget. It is returned bylayout()
.See also
- PySide2.QtWidgets.QBoxLayout.Direction¶
This type is used to determine the direction of a box layout.
Constant
Description
QBoxLayout.LeftToRight
Horizontal from left to right.
QBoxLayout.RightToLeft
Horizontal from right to left.
QBoxLayout.TopToBottom
Vertical from top to bottom.
QBoxLayout.BottomToTop
Vertical from bottom to top.
- PySide2.QtWidgets.QBoxLayout.addLayout(layout[, stretch=0])¶
- Parameters:
layout –
PySide2.QtWidgets.QLayout
stretch – int
Adds
layout
to the end of the box, with serial stretch factorstretch
.See also
insertLayout()
addItem()
addWidget()
- PySide2.QtWidgets.QBoxLayout.addSpacerItem(spacerItem)¶
- Parameters:
spacerItem –
PySide2.QtWidgets.QSpacerItem
Adds
spacerItem
to the end of this box layout.See also
- PySide2.QtWidgets.QBoxLayout.addSpacing(size)¶
- Parameters:
size – int
Adds a non-stretchable space (a
QSpacerItem
) with sizesize
to the end of this box layout.QBoxLayout
provides default margin and spacing. This function adds additional space.See also
insertSpacing()
addItem()
QSpacerItem
- PySide2.QtWidgets.QBoxLayout.addStretch([stretch=0])¶
- Parameters:
stretch – int
Adds a stretchable space (a
QSpacerItem
) with zero minimum size and stretch factorstretch
to the end of this box layout.See also
insertStretch()
addItem()
QSpacerItem
- PySide2.QtWidgets.QBoxLayout.addStrut(arg__1)¶
- Parameters:
arg__1 – int
Limits the perpendicular dimension of the box (e.g. height if the box is
LeftToRight
) to a minimum ofsize
. Other constraints may increase the limit.See also
addItem()
- PySide2.QtWidgets.QBoxLayout.addWidget(arg__1[, stretch=0[, alignment=Qt.Alignment()]])¶
- Parameters:
arg__1 –
PySide2.QtWidgets.QWidget
stretch – int
alignment –
Alignment
Adds
widget
to the end of this box layout, with a stretch factor ofstretch
and alignmentalignment
.The stretch factor applies only in the
direction
of theQBoxLayout
, and is relative to the other boxes and widgets in thisQBoxLayout
. Widgets and boxes with higher stretch factors grow more.If the stretch factor is 0 and nothing else in the
QBoxLayout
has a stretch factor greater than zero, the space is distributed according to theQWidget
:sizePolicy() of each widget that’s involved.The alignment is specified by
alignment
. The default alignment is 0, which means that the widget fills the entire cell.See also
insertWidget()
addItem()
addLayout()
addStretch()
addSpacing()
addStrut()
- PySide2.QtWidgets.QBoxLayout.direction()¶
- Return type:
Returns the direction of the box.
addWidget()
andaddSpacing()
work in this direction; the stretch stretches in this direction.See also
setDirection()
Direction
addWidget()
addSpacing()
- PySide2.QtWidgets.QBoxLayout.insertItem(index, arg__2)¶
- Parameters:
index – int
arg__2 –
PySide2.QtWidgets.QLayoutItem
Inserts
item
into this box layout at positionindex
. Ifindex
is negative, the item is added at the end.See also
addItem()
insertWidget()
insertLayout()
insertStretch()
insertSpacing()
- PySide2.QtWidgets.QBoxLayout.insertLayout(index, layout[, stretch=0])¶
- Parameters:
index – int
layout –
PySide2.QtWidgets.QLayout
stretch – int
Inserts
layout
at positionindex
, with stretch factorstretch
. Ifindex
is negative, the layout is added at the end.layout
becomes a child of the box layout.See also
- PySide2.QtWidgets.QBoxLayout.insertSpacerItem(index, spacerItem)¶
- Parameters:
index – int
spacerItem –
PySide2.QtWidgets.QSpacerItem
Inserts
spacerItem
at positionindex
, with zero minimum size and stretch factor. Ifindex
is negative the space is added at the end.
- PySide2.QtWidgets.QBoxLayout.insertSpacing(index, size)¶
- Parameters:
index – int
size – int
Inserts a non-stretchable space (a
QSpacerItem
) at positionindex
, with sizesize
. Ifindex
is negative the space is added at the end.The box layout has default margin and spacing. This function adds additional space.
See also
- PySide2.QtWidgets.QBoxLayout.insertStretch(index[, stretch=0])¶
- Parameters:
index – int
stretch – int
Inserts a stretchable space (a
QSpacerItem
) at positionindex
, with zero minimum size and stretch factorstretch
. Ifindex
is negative the space is added at the end.See also
- PySide2.QtWidgets.QBoxLayout.insertWidget(index, widget[, stretch=0[, alignment=Qt.Alignment()]])¶
- Parameters:
index – int
widget –
PySide2.QtWidgets.QWidget
stretch – int
alignment –
Alignment
Inserts
widget
at positionindex
, with stretch factorstretch
and alignmentalignment
. Ifindex
is negative, the widget is added at the end.The stretch factor applies only in the
direction
of theQBoxLayout
, and is relative to the other boxes and widgets in thisQBoxLayout
. Widgets and boxes with higher stretch factors grow more.If the stretch factor is 0 and nothing else in the
QBoxLayout
has a stretch factor greater than zero, the space is distributed according to theQWidget
:sizePolicy() of each widget that’s involved.The alignment is specified by
alignment
. The default alignment is 0, which means that the widget fills the entire cell.See also
- PySide2.QtWidgets.QBoxLayout.setDirection(arg__1)¶
- Parameters:
arg__1 –
Direction
Sets the direction of this layout to
direction
.See also
- PySide2.QtWidgets.QBoxLayout.setStretch(index, stretch)¶
- Parameters:
index – int
stretch – int
Sets the stretch factor at position
index
. tostretch
.See also
- PySide2.QtWidgets.QBoxLayout.setStretchFactor(l, stretch)¶
- Parameters:
stretch – int
- Return type:
bool
This is an overloaded function.
Sets the stretch factor for the layout
layout
tostretch
and returnstrue
iflayout
is found in this layout (not including child layouts); otherwise returnsfalse
.
- PySide2.QtWidgets.QBoxLayout.setStretchFactor(w, stretch)
- Parameters:
stretch – int
- Return type:
bool
Sets the stretch factor for
widget
tostretch
and returns true ifwidget
is found in this layout (not including child layouts); otherwise returnsfalse
.See also
- PySide2.QtWidgets.QBoxLayout.stretch(index)¶
- Parameters:
index – int
- Return type:
int
Returns the stretch factor at position
index
.See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.