Skip to content

PythonQt.QtGui.QBoxLayout

QBoxLayout

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QBoxLayout takes the space it gets (from its parent layout or from the parentWidget()), divides it up into a row of boxes, and makes each managed widget fill one box.

Horizontal box layout with five child
widgets

If the QBoxLayout's orientation is Qt::Horizontal 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).

Vertical box layout with five child
widgets

If the QBoxLayout's orientation is Qt::Vertical, 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 (for Qt::Horizontal boxes) or QVBoxLayout (for Qt::Vertical boxes). You can also use the QBoxLayout constructor directly, specifying its direction as LeftToRight, RightToLeft, TopToBottom, or BottomToTop.

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 the QBoxLayout 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 another QLayout to the row and set that layout's stretch factor.

Use insertWidget(), insertSpacing(), insertStretch() or insertLayout() 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 the QBoxLayout's four sides.
  • setSpacing() sets the width between neighboring boxes. (You can use addSpacing() 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(). Calling QWidget::hide() on a widget also effectively removes the widget from the layout until QWidget::show() is called.

You will almost always want to use QVBoxLayout and QHBoxLayout rather than QBoxLayout because of their convenient constructors.

Source: https://doc.qt.io/archives/qt-5.15/qboxlayout.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
BottomToTop attribute Any
Direction attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
Down attribute Any
LeftToRight attribute Any (shared captured text)
RightToLeft attribute Any (shared captured text)
SetDefaultConstraint attribute Any
SetFixedSize attribute Any
SetMaximumSize attribute Any
SetMinAndMaxSize attribute Any
SetMinimumSize attribute Any
SetNoConstraint attribute Any
SizeConstraint attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
TopToBottom attribute Any
Up attribute Any
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
activate function (self) -> bool X.activate() -> bool
addChildLayout function (self, l: Any) -> Any
addChildWidget function (self, w: Any) -> Any
addItem function (self, arg__1: Any) -> None Reimplements: [QLayout::addItem](https://doc.qt.io/archives/qt-5.15/qlayout.html#addItem)(QLayoutItem *item).
addLayout function (self, layout: Any, stretch: int) -> None X.addLayout(layout, stretch)
addSpacerItem function (self, spacerItem: Any) -> None Adds spacerItem to the end of this box layout.
addSpacing function (self, size: int) -> None Adds a non-stretchable space (a [QSpacerItem](https://doc.qt.io/archives/qt-5.15/qspaceritem.html)) with size size to the end of this box layout.
addStretch function (self, stretch: int) -> None Adds a stretchable space (a [QSpacerItem](https://doc.qt.io/archives/qt-5.15/qspaceritem.html)) with zero minimum size and stretch factor stretch to the end of this box layout.
addStrut function (self, arg__1: int) -> None Limits the perpendicular dimension of the box (e.g. height if the box is [LeftToRight](https://doc.qt.io/archives/qt-5.15/qboxlayout.html#Direction-enum)) to a minimum of size.
addWidget function (self, arg__1: Any, stretch: Any, alignment: Any) -> None X.addWidget(arg__1, stretch, alignment)
adoptLayout function (self, layout: Any) -> bool X.adoptLayout(layout) -> bool
alignment function (self) -> Any
alignmentRect function (self, arg__1: Any) -> Any X.alignmentRect(arg__1) -> PythonQt.QtCore.QRect
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
childEvent function (self, e: Any) -> Any
children function (self) -> tuple X.children() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
closestAcceptableSize function (self, w: Any, s: Any) -> Any X.closestAcceptableSize(w, s) -> PythonQt.QtCore.QSize
connect function (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool X.connect(signal, receiver, slot, type) -> bool (shared captured text)
contentsMargins function (self) -> Any X.contentsMargins() -> PythonQt.QtGui.QMargins (shared captured text)
contentsRect function (self) -> Any X.contentsRect() -> PythonQt.QtCore.QRect (shared captured text)
controlTypes function (self) -> Any
count function (self) -> int X.count() -> int
customEvent function (self, event: Any) -> Any (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
deleteLater function (self) -> Any (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QBoxLayout.destroyed; argument details are not documented.
direction function (self) -> Any Returns the direction of the box.
disconnect function (self, signal: Any, receiver: Any, slot: Any) -> bool X.disconnect(signal, receiver, slot) -> bool (shared captured text)
dumpObjectInfo function (self) -> Any (shared captured text)
dumpObjectTree function (self) -> Any (shared captured text)
dynamicPropertyNames function (self) -> Any (shared captured text)
event function (self, event: Any) -> bool X.event(event) -> bool (shared captured text)
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
expandingDirections function (self) -> Any Reimplements: [QLayout::expandingDirections](https://doc.qt.io/archives/qt-5.15/qlayout.html#expandingDirections)() const.
findChild function (self, type: Any, name: Any) -> Any X.findChild(type, name) -> PythonQt.private.QObject (shared captured text)
findChildren function (self, type: Any, name: Any) -> tuple X.findChildren(type, name) -> tuple (shared captured text)
geometry function (self) -> Any X.geometry() -> PythonQt.QtCore.QRect
hasHeightForWidth function (self) -> bool X.hasHeightForWidth() -> bool
heightForWidth function (self, arg__1: int) -> int X.heightForWidth(arg__1) -> int
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
indexOf function (self, arg__1: Any) -> int X.indexOf(arg__1) -> int
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
insertItem function (self, index: int, arg__2: Any) -> None X.insertItem(index, arg__2)
insertLayout function (self, index: int, layout: Any, stretch: int) -> None X.insertLayout(index, layout, stretch)
insertSpacerItem function (self, index: int, spacerItem: Any) -> None X.insertSpacerItem(index, spacerItem)
insertSpacing function (self, index: int, size: int) -> None X.insertSpacing(index, size)
insertStretch function (self, index: int, stretch: int) -> None X.insertStretch(index, stretch)
insertWidget function (self, index: int, widget: Any, stretch: int, alignment: Any) -> None X.insertWidget(index, widget, stretch, alignment)
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
invalidate function (self) -> None Reimplements: [QLayout::invalidate](https://doc.qt.io/archives/qt-5.15/qlayout.html#invalidate)().
isEmpty function (self) -> bool X.isEmpty() -> bool
isEnabled function (self) -> bool X.isEnabled() -> bool (shared captured text)
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isWidgetType function (self) -> bool X.isWidgetType() -> bool (shared captured text)
isWindowType function (self) -> bool X.isWindowType() -> bool (shared captured text)
itemAt function (self, arg__1: int) -> Any X.itemAt(arg__1) -> PythonQt.QtGui.QLayoutItem
killTimer function (self, id: Any) -> Any (shared captured text)
layout function (self) -> Any X.layout() -> PythonQt.QtGui.QLayout (shared captured text)
margin attribute Any
maximumSize function (self) -> Any X.maximumSize() -> PythonQt.QtCore.QSize
menuBar function (self) -> Any X.menuBar() -> PythonQt.QtGui.QWidget
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
minimumHeightForWidth function (self, arg__1: int) -> int X.minimumHeightForWidth(arg__1) -> int
minimumSize function (self) -> Any X.minimumSize() -> PythonQt.QtCore.QSize
moveToThread function (self, thread: Any) -> Any (shared captured text)
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QBoxLayout.objectNameChanged; argument details are not documented.
parent function (self) -> Any X.parent() -> PythonQt.private.QObject (shared captured text)
parentWidget function (self) -> Any X.parentWidget() -> PythonQt.QtGui.QWidget (shared captured text)
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
removeItem function (self, arg__1: Any) -> Any
removeWidget function (self, w: Any) -> Any
replaceWidget function (self, *args: Any, **kwargs: Any) -> Any X.replaceWidget(from, to, options) -> PythonQt.QtGui.QLayoutItem
sender function (self) -> Any X.sender() -> PythonQt.private.QObject (shared captured text)
senderSignalIndex function (self) -> int X.senderSignalIndex() -> int (shared captured text)
setAlignment function (self, l: Any, alignment: Any) -> bool X.setAlignment(l, alignment) -> bool
setContentsMargins function (self, left: Any, top: Any, right: Any, bottom: Any) -> Any X.setContentsMargins(left, top, right, bottom) (shared captured text)
setDirection function (self, arg__1: Any) -> None Sets the direction of this layout to direction.
setEnabled function (self, arg__1: Any) -> Any
setGeometry function (self, arg__1: Any) -> None Reimplements: [QLayout::setGeometry](https://doc.qt.io/archives/qt-5.15/qlayout.html#setGeometry)(const QRect \&r).
setMargin function (self, arg__1: Any) -> Any
setMenuBar function (self, w: Any) -> Any
setObjectName function (self, name: Any) -> Any (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setSizeConstraint function (self, arg__1: Any) -> Any
setSpacing function (self, spacing: int) -> None Reimplements [QLayout::setSpacing](https://doc.qt.io/archives/qt-5.15/qlayout.html#spacing-prop)().
setStretch function (self, index: int, stretch: int) -> None X.setStretch(index, stretch)
setStretchFactor function (self, l: Any, stretch: int) -> bool X.setStretchFactor(l, stretch) -> bool
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
sizeConstraint attribute Any
sizeHint function (self) -> Any X.sizeHint() -> PythonQt.QtCore.QSize
spacerItem function (self) -> Any X.spacerItem() -> PythonQt.QtGui.QSpacerItem
spacing attribute int Reimplements [QLayout::spacing](https://doc.qt.io/archives/qt-5.15/qlayout.html#spacing-prop)().
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
stretch function (self, index: int) -> int X.stretch(index) -> int
takeAt function (self, arg__1: int) -> Any X.takeAt(arg__1) -> PythonQt.QtGui.QLayoutItem
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
totalHeightForWidth function (self, w: Any) -> int X.totalHeightForWidth(w) -> int
totalMaximumSize function (self) -> Any X.totalMaximumSize() -> PythonQt.QtCore.QSize
totalMinimumSize function (self) -> Any X.totalMinimumSize() -> PythonQt.QtCore.QSize
totalSizeHint function (self) -> Any X.totalSizeHint() -> PythonQt.QtCore.QSize
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)
update function (self) -> Any
widget function (self) -> Any X.widget() -> PythonQt.QtGui.QWidget
widgetEvent function (self, arg__1: Any) -> Any