Table Of Contents

Previous topic

QFormLayout

Next topic

QVBoxLayout

QBoxLayout

Inheritance diagram of QBoxLayout

Inherited by: QVBoxLayout, QHBoxLayout

Synopsis

Functions

Detailed Description

The PySide.QtGui.QBoxLayout class lines up child widgets horizontally or vertically.

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

../../_images/qhboxlayout-with-5-children.png

If the PySide.QtGui.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).

../../_images/qvboxlayout-with-5-children.png

If the PySide.QtGui.QBoxLayout ‘s orientation is Qt.Vertical , the boxes are placed in a column, again with suitable sizes.

The easiest way to create a PySide.QtGui.QBoxLayout is to use one of the convenience classes, e.g. PySide.QtGui.QHBoxLayout (for Qt.Horizontal boxes) or PySide.QtGui.QVBoxLayout (for Qt.Vertical boxes). You can also use the PySide.QtGui.QBoxLayout constructor directly, specifying its direction as LeftToRight , RightToLeft , TopToBottom , or BottomToTop .

If the PySide.QtGui.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-> PySide.QtGui.QBoxLayout.addLayout() .

Once you have done this, you can add boxes to the PySide.QtGui.QBoxLayout using one of four functions:

Use PySide.QtGui.QBoxLayout.insertWidget() , PySide.QtGui.QBoxLayout.insertSpacing() , PySide.QtGui.QBoxLayout.insertStretch() or PySide.QtGui.QBoxLayout.insertLayout() to insert a box at a specified position in the layout.

PySide.QtGui.QBoxLayout also includes two margin widths:

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 PySide.QtGui.QLayout.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 PySide.QtGui.QVBoxLayout and PySide.QtGui.QHBoxLayout rather than PySide.QtGui.QBoxLayout because of their convenient constructors.

class PySide.QtGui.QBoxLayout(arg__1[, parent=None])
Parameters:

Constructs a new PySide.QtGui.QBoxLayout with direction dir and parent widget parent .

PySide.QtGui.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.
PySide.QtGui.QBoxLayout.addLayout(layout[, stretch=0])
Parameters:

Adds layout to the end of the box, with serial stretch factor stretch .

PySide.QtGui.QBoxLayout.addSpacerItem(spacerItem)
Parameters:spacerItemPySide.QtGui.QSpacerItem

Adds spacerItem to the end of this box layout.

PySide.QtGui.QBoxLayout.addSpacing(size)
Parameters:sizePySide.QtCore.int

Adds a non-stretchable space (a PySide.QtGui.QSpacerItem ) with size size to the end of this box layout. PySide.QtGui.QBoxLayout provides default margin and spacing. This function adds additional space.

See also

PySide.QtGui.QBoxLayout.insertSpacing() PySide.QtGui.QBoxLayout.addItem() PySide.QtGui.QSpacerItem

PySide.QtGui.QBoxLayout.addStretch([stretch=0])
Parameters:stretchPySide.QtCore.int

Adds a stretchable space (a PySide.QtGui.QSpacerItem ) with zero minimum size and stretch factor stretch to the end of this box layout.

See also

PySide.QtGui.QBoxLayout.insertStretch() PySide.QtGui.QBoxLayout.addItem() PySide.QtGui.QSpacerItem

PySide.QtGui.QBoxLayout.addStrut(arg__1)
Parameters:arg__1PySide.QtCore.int

Limits the perpendicular dimension of the box (e.g. height if the box is LeftToRight ) to a minimum of size . Other constraints may increase the limit.

See also

PySide.QtGui.QBoxLayout.addItem()

PySide.QtGui.QBoxLayout.addWidget(arg__1[, stretch=0[, alignment=0]])
Parameters:
  • arg__1PySide.QtGui.QWidget
  • stretchPySide.QtCore.int
  • alignmentPySide.QtCore.Qt.Alignment
PySide.QtGui.QBoxLayout.direction()
Return type:PySide.QtGui.QBoxLayout.Direction

Returns the direction of the box. PySide.QtGui.QBoxLayout.addWidget() and PySide.QtGui.QBoxLayout.addSpacing() work in this direction; the stretch stretches in this direction.

PySide.QtGui.QBoxLayout.insertItem(index, arg__2)
Parameters:

Inserts item into this box layout at position index . If index is negative, the item is added at the end.

PySide.QtGui.QBoxLayout.insertLayout(index, layout[, stretch=0])
Parameters:

Inserts layout at position index , with stretch factor stretch . If index is negative, the layout is added at the end.

layout becomes a child of the box layout.

PySide.QtGui.QBoxLayout.insertSpacerItem(index, spacerItem)
Parameters:

Inserts spacerItem at position index , with zero minimum size and stretch factor. If index is negative the space is added at the end.

PySide.QtGui.QBoxLayout.insertSpacing(index, size)
Parameters:
  • indexPySide.QtCore.int
  • sizePySide.QtCore.int

Inserts a non-stretchable space (a PySide.QtGui.QSpacerItem ) at position index , with size size . If index is negative the space is added at the end.

The box layout has default margin and spacing. This function adds additional space.

PySide.QtGui.QBoxLayout.insertStretch(index[, stretch=0])
Parameters:
  • indexPySide.QtCore.int
  • stretchPySide.QtCore.int

Inserts a stretchable space (a PySide.QtGui.QSpacerItem ) at position index , with zero minimum size and stretch factor stretch . If index is negative the space is added at the end.

PySide.QtGui.QBoxLayout.insertWidget(index, widget[, stretch=0[, alignment=0]])
Parameters:
  • indexPySide.QtCore.int
  • widgetPySide.QtGui.QWidget
  • stretchPySide.QtCore.int
  • alignmentPySide.QtCore.Qt.Alignment
PySide.QtGui.QBoxLayout.setDirection(arg__1)
Parameters:arg__1PySide.QtGui.QBoxLayout.Direction

Sets the direction of this layout to direction .

PySide.QtGui.QBoxLayout.setStretch(index, stretch)
Parameters:
  • indexPySide.QtCore.int
  • stretchPySide.QtCore.int

Sets the stretch factor at position index . to stretch .

PySide.QtGui.QBoxLayout.setStretchFactor(w, stretch)
Parameters:
Return type:

PySide.QtCore.bool

Sets the stretch factor for widget to stretch and returns true if widget is found in this layout (not including child layouts); otherwise returns false.

PySide.QtGui.QBoxLayout.setStretchFactor(l, stretch)
Parameters:
Return type:

PySide.QtCore.bool

This is an overloaded function.

Sets the stretch factor for the layout layout to stretch and returns true if layout is found in this layout (not including child layouts); otherwise returns false.

PySide.QtGui.QBoxLayout.stretch(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.int

Returns the stretch factor at position index .