QLayout

Inheritance diagram of QLayout

Inherited by: QStackedLayout, QGridLayout, QFormLayout, QBoxLayout, QVBoxLayout, QHBoxLayout

Synopsis

Functions

Virtual functions

Static functions

Detailed Description

The PySide.QtGui.QLayout class is the base class of geometry managers.

This is an abstract base class inherited by the concrete classes PySide.QtGui.QBoxLayout , PySide.QtGui.QGridLayout , PySide.QtGui.QFormLayout , and PySide.QtGui.QStackedLayout .

For users of PySide.QtGui.QLayout subclasses or of PySide.QtGui.QMainWindow there is seldom any need to use the basic functions provided by PySide.QtGui.QLayout , such as PySide.QtGui.QLayout.setSizeConstraint() or PySide.QtGui.QLayout.setMenuBar() . See Layout Management for more information.

To make your own layout manager, implement the functions PySide.QtGui.QLayout.addItem() , PySide.QtGui.QLayoutItem.sizeHint() , PySide.QtGui.QLayout.setGeometry() , PySide.QtGui.QLayout.itemAt() and PySide.QtGui.QLayout.takeAt() . You should also implement PySide.QtGui.QLayout.minimumSize() to ensure your layout isn’t resized to zero size if there is too little space. To support children whose heights depend on their widths, implement PySide.QtGui.QLayoutItem.hasHeightForWidth() and PySide.QtGui.QLayoutItem.heightForWidth() . See the Border Layout and Flow Layout examples for more information about implementing custom layout managers.

Geometry management stops when the layout manager is deleted.

See also

PySide.QtGui.QLayoutItem Layout Management Basic Layouts Example Border Layout Example Flow Layout Example

class PySide.QtGui.QLayout
class PySide.QtGui.QLayout(parent)
Parameters:parentPySide.QtGui.QWidget

Constructs a new child PySide.QtGui.QLayout .

This layout has to be inserted into another layout before geometry management will work.

Constructs a new top-level PySide.QtGui.QLayout , with parent parent . parent may not be 0.

There can be only one top-level layout for a widget. It is returned by QWidget.layout() .

PySide.QtGui.QLayout.SizeConstraint

The possible values are:

Constant Description
QLayout.SetDefaultConstraint The main widget’s minimum size is set to PySide.QtGui.QLayout.minimumSize() , unless the widget already has a minimum size.
QLayout.SetFixedSize The main widget’s size is set to PySide.QtGui.QLayoutItem.sizeHint() ; it cannot be resized at all.
QLayout.SetMinimumSize The main widget’s minimum size is set to PySide.QtGui.QLayout.minimumSize() ; it cannot be smaller.
QLayout.SetMaximumSize The main widget’s maximum size is set to PySide.QtGui.QLayout.maximumSize() ; it cannot be larger.
QLayout.SetMinAndMaxSize The main widget’s minimum size is set to PySide.QtGui.QLayout.minimumSize() and its maximum size is set to PySide.QtGui.QLayout.maximumSize() .
QLayout.SetNoConstraint The widget is not constrained.
PySide.QtGui.QLayout.activate()
Return type:PySide.QtCore.bool

Redoes the layout for PySide.QtGui.QLayout.parentWidget() if necessary.

You should generally not need to call this because it is automatically called at the most appropriate times. It returns true if the layout was redone.

static PySide.QtGui.QLayout.activateRecursiveHelper(item)
Parameters:itemPySide.QtGui.QLayoutItem
PySide.QtGui.QLayout.addChildLayout(l)
Parameters:lPySide.QtGui.QLayout

This function is called from addLayout() or insertLayout() functions in subclasses to add layout l as a sub-layout.

The only scenario in which you need to call it directly is if you implement a custom layout that supports nested layouts.

PySide.QtGui.QLayout.addChildWidget(w)
Parameters:wPySide.QtGui.QWidget

This function is called from addWidget() functions in subclasses to add w as a child widget.

If w is already in a layout, this function will give a warning and remove w from the layout. This function must therefore be called before adding w to the layout’s data structure.

PySide.QtGui.QLayout.addItem(arg__1)
Parameters:arg__1PySide.QtGui.QLayoutItem

Implemented in subclasses to add an item . How it is added is specific to each subclass.

This function is not usually called in application code. To add a widget to a layout, use the PySide.QtGui.QLayout.addWidget() function; to add a child layout, use the addLayout() function provided by the relevant PySide.QtGui.QLayout subclass.

Note

The ownership of item is transferred to the layout, and it’s the layout’s responsibility to delete it.

PySide.QtGui.QLayout.addWidget(w)
Parameters:wPySide.QtGui.QWidget

Adds widget w to this layout in a manner specific to the layout. This function uses PySide.QtGui.QLayout.addItem() .

PySide.QtGui.QLayout.alignmentRect(arg__1)
Parameters:arg__1PySide.QtCore.QRect
Return type:PySide.QtCore.QRect

Returns the rectangle that should be covered when the geometry of this layout is set to r , provided that this layout supports PySide.QtGui.QLayout.setAlignment() .

The result is derived from PySide.QtGui.QLayoutItem.sizeHint() and expanding(). It is never larger than r .

static PySide.QtGui.QLayout.closestAcceptableSize(w, s)
Parameters:
Return type:

PySide.QtCore.QSize

Returns a size that satisfies all size constraints on widget , including PySide.QtGui.QLayoutItem.heightForWidth() and that is as close as possible to size .

PySide.QtGui.QLayout.contentsMargins()
Return type:PySide.QtCore.QMargins

Returns the margins used around the layout.

By default, PySide.QtGui.QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

PySide.QtGui.QLayout.contentsRect()
Return type:PySide.QtCore.QRect

Returns the layout’s PySide.QtGui.QLayout.geometry() rectangle, but taking into account the contents margins.

PySide.QtGui.QLayout.count()
Return type:PySide.QtCore.int

Must be implemented in subclasses to return the number of items in the layout.

PySide.QtGui.QLayout.getContentsMargins()

Extracts the left, top, right, and bottom margins used around the layout, and assigns them to *``left`` , *``top`` , *``right`` , and *``bottom`` (unless they are null pointers).

By default, PySide.QtGui.QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also

PySide.QtGui.QLayout.setContentsMargins() QStyle.pixelMetric() PM_LayoutLeftMargin PM_LayoutTopMargin PM_LayoutRightMargin PM_LayoutBottomMargin

PySide.QtGui.QLayout.indexOf(arg__1)
Parameters:arg__1PySide.QtGui.QWidget
Return type:PySide.QtCore.int

Searches for widget widget in this layout (not including child layouts).

Returns the index of widget , or -1 if widget is not found.

The default implementation iterates over all items using PySide.QtGui.QLayout.itemAt()

PySide.QtGui.QLayout.isEnabled()
Return type:PySide.QtCore.bool

Returns true if the layout is enabled; otherwise returns false.

PySide.QtGui.QLayout.itemAt(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtGui.QLayoutItem

Must be implemented in subclasses to return the layout item at index . If there is no such item, the function must return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.

This function can be used to iterate over a layout. The following code will draw a rectangle for each layout item in the layout structure of the widget.

def paintLayout(self, painter, item):
    layout = item.layout()

    if layout:
        for layout_item in layout:
            self.paintLayout(painter, layout_item)

    painter.drawRect(item.geometry())

def paintEvent(self, event):
    painter = QPainter(self)
    if self.layout():
        self.paintLayout(painter, self.layout())
PySide.QtGui.QLayout.menuBar()
Return type:PySide.QtGui.QWidget

Returns the menu bar set for this layout, or 0 if no menu bar is set.

PySide.QtGui.QLayout.parentWidget()
Return type:PySide.QtGui.QWidget

Returns the parent widget of this layout, or 0 if this layout is not installed on any widget.

If the layout is a sub-layout, this function returns the parent widget of the parent layout.

See also

PySide.QtCore.QObject.parent()

PySide.QtGui.QLayout.removeItem(arg__1)
Parameters:arg__1PySide.QtGui.QLayoutItem

Removes the layout item item from the layout. It is the caller’s responsibility to delete the item.

Notice that item can be a layout (since PySide.QtGui.QLayout inherits PySide.QtGui.QLayoutItem ).

PySide.QtGui.QLayout.removeWidget(w)
Parameters:wPySide.QtGui.QWidget

Removes the widget widget from the layout. After this call, it is the caller’s responsibility to give the widget a reasonable geometry or to put the widget back into a layout.

Note

The ownership of widget remains the same as when it was added.

PySide.QtGui.QLayout.setAlignment(w, alignment)
Parameters:
Return type:

PySide.QtCore.bool

PySide.QtGui.QLayout.setAlignment(l, alignment)
Parameters:
Return type:

PySide.QtCore.bool

PySide.QtGui.QLayout.setContentsMargins(left, top, right, bottom)
Parameters:
  • leftPySide.QtCore.int
  • topPySide.QtCore.int
  • rightPySide.QtCore.int
  • bottomPySide.QtCore.int

Sets the left , top , right , and bottom margins to use around the layout.

By default, PySide.QtGui.QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also

PySide.QtGui.QLayout.contentsMargins() PySide.QtGui.QLayout.getContentsMargins() QStyle.pixelMetric() PM_LayoutLeftMargin PM_LayoutTopMargin PM_LayoutRightMargin PM_LayoutBottomMargin

PySide.QtGui.QLayout.setContentsMargins(margins)
Parameters:marginsPySide.QtCore.QMargins

Sets the margins to use around the layout.

By default, PySide.QtGui.QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

PySide.QtGui.QLayout.setEnabled(arg__1)
Parameters:arg__1PySide.QtCore.bool

Enables this layout if enable is true, otherwise disables it.

An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.

By default all layouts are enabled.

PySide.QtGui.QLayout.setMenuBar(w)
Parameters:wPySide.QtGui.QWidget

Tells the geometry manager to place the menu bar widget at the top of PySide.QtGui.QLayout.parentWidget() , outside QWidget.contentsMargins() . All child widgets are placed below the bottom edge of the menu bar.

PySide.QtGui.QLayout.setSizeConstraint(arg__1)
Parameters:arg__1PySide.QtGui.QLayout.SizeConstraint

This property holds the resize mode of the layout.

The default mode is SetDefaultConstraint .

PySide.QtGui.QLayout.setSpacing(arg__1)
Parameters:arg__1PySide.QtCore.int

This property holds the spacing between widgets inside the layout.

If no value is explicitly set, the layout’s spacing is inherited from the parent layout, or from the style settings for the parent widget.

For PySide.QtGui.QGridLayout and PySide.QtGui.QFormLayout , it is possible to set different horizontal and vertical spacings using PySide.QtGui.QGridLayout.setHorizontalSpacing() and PySide.QtGui.QGridLayout.setVerticalSpacing() . In that case, PySide.QtGui.QLayout.spacing() returns -1.

PySide.QtGui.QLayout.sizeConstraint()
Return type:PySide.QtGui.QLayout.SizeConstraint

This property holds the resize mode of the layout.

The default mode is SetDefaultConstraint .

PySide.QtGui.QLayout.spacing()
Return type:PySide.QtCore.int

This property holds the spacing between widgets inside the layout.

If no value is explicitly set, the layout’s spacing is inherited from the parent layout, or from the style settings for the parent widget.

For PySide.QtGui.QGridLayout and PySide.QtGui.QFormLayout , it is possible to set different horizontal and vertical spacings using PySide.QtGui.QGridLayout.setHorizontalSpacing() and PySide.QtGui.QGridLayout.setVerticalSpacing() . In that case, PySide.QtGui.QLayout.spacing() returns -1.

PySide.QtGui.QLayout.takeAt(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtGui.QLayoutItem

Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered consecutively from 0. If an item is removed, other items will be renumbered.

The following code fragment shows a safe way to remove all items from a layout:

child = layout.takeAt(0)
while child:
    ...
    del child
PySide.QtGui.QLayout.totalHeightForWidth(w)
Parameters:wPySide.QtCore.int
Return type:PySide.QtCore.int

Also takes contentsMargins and menu bar into account.

PySide.QtGui.QLayout.totalMaximumSize()
Return type:PySide.QtCore.QSize

Also takes contentsMargins and menu bar into account.

PySide.QtGui.QLayout.totalMinimumSize()
Return type:PySide.QtCore.QSize

Also takes contentsMargins and menu bar into account.

PySide.QtGui.QLayout.totalSizeHint()
Return type:PySide.QtCore.QSize

Also takes contentsMargins and menu bar into account.

PySide.QtGui.QLayout.update()

Updates the layout for PySide.QtGui.QLayout.parentWidget() .

You should generally not need to call this because it is automatically called at the most appropriate times.

See also

PySide.QtGui.QLayout.activate() PySide.QtGui.QLayout.invalidate()

PySide.QtGui.QLayout.widgetEvent(arg__1)
Parameters:arg__1PySide.QtCore.QEvent

Performs child widget layout when the parent widget is resized. Also handles removal of widgets. e is the event