Inheritance diagram of PySide2.QtWidgets.QLayoutItem

Inherited by: QWidgetItem, QSpacerItem, QLayout, QGridLayout, QBoxLayout, QHBoxLayout, QVBoxLayout, QStackedLayout, QFormLayout



Virtual functions

Detailed Description

The PySide2.QtWidgets.QLayoutItem class provides an abstract item that a PySide2.QtWidgets.QLayout manipulates.

This is used by custom layouts.

Pure virtual functions are provided to return information about the layout, including, PySide2.QtWidgets.QLayoutItem.sizeHint() , PySide2.QtWidgets.QLayoutItem.minimumSize() , PySide2.QtWidgets.QLayoutItem.maximumSize() and expanding().

The layout’s geometry can be set and retrieved with PySide2.QtWidgets.QLayoutItem.setGeometry() and PySide2.QtWidgets.QLayoutItem.geometry() , and its alignment with PySide2.QtWidgets.QLayoutItem.setAlignment() and PySide2.QtWidgets.QLayoutItem.alignment() .

PySide2.QtWidgets.QLayoutItem.isEmpty() returns whether the layout item is empty. If the concrete item is a PySide2.QtWidgets.QWidget , it can be retrieved using PySide2.QtWidgets.QLayoutItem.widget() . Similarly for PySide2.QtWidgets.QLayoutItem.layout() and PySide2.QtWidgets.QLayoutItem.spacerItem() .

Some layouts have width and height interdependencies. These can be expressed using PySide2.QtWidgets.QLayoutItem.hasHeightForWidth() , PySide2.QtWidgets.QLayoutItem.heightForWidth() , and PySide2.QtWidgets.QLayoutItem.minimumHeightForWidth() . For more explanation see the Qt Quarterly article Trading Height for Width.

class PySide2.QtWidgets.QLayoutItem([alignment=Qt.Alignment()])

Constructs a layout item with an alignment . Not all subclasses support alignment.

Return type:PySide2.QtCore.Qt.Alignment

Returns the alignment of this item.

Return type:PySide2.QtWidgets.QSizePolicy.ControlTypes

Returns the control type(s) for the layout item. For a PySide2.QtWidgets.QWidgetItem , the control type comes from the widget’s size policy; for a PySide2.QtWidgets.QLayoutItem , the control types is derived from the layout’s contents.

Return type:PySide2.QtCore.Qt.Orientations

Returns whether this layout item can make use of more space than PySide2.QtWidgets.QLayoutItem.sizeHint() . A value of Qt.Vertical or Qt.Horizontal means that it wants to grow in only one dimension, whereas Qt.Vertical | Qt.Horizontal means that it wants to grow in both dimensions.

Return type:PySide2.QtCore.QRect

Returns the rectangle covered by this layout item.

Return type:PySide2.QtCore.bool

Returns true if this layout’s preferred height depends on its width; otherwise returns false . The default implementation returns false.

Reimplement this function in layout managers that support height for width.

Return type:PySide2.QtCore.int

Returns the preferred height for this layout item, given the width, which is not used in this default implementation.

The default implementation returns -1, indicating that the preferred height is independent of the width of the item. Using the function PySide2.QtWidgets.QLayoutItem.hasHeightForWidth() will typically be much faster than calling this function and testing for -1.

Reimplement this function in layout managers that support height for width. A typical implementation will look like this:

def heightForWidth(self, w):
    if cache_dirty or cached_width != w:
        h = calculateHeightForWidth(w)
        self.cached_hfw = h
        return h
    return cached_hfw

Caching is strongly recommended; without it layout will take exponential time.


Invalidates any cached information in this layout item.

Return type:PySide2.QtCore.bool

Implemented in subclasses to return whether this item is empty, i.e. whether it contains any widgets.

Return type:PySide2.QtWidgets.QLayout

If this item is a PySide2.QtWidgets.QLayout , it is returned as a PySide2.QtWidgets.QLayout ; otherwise 0 is returned. This function provides type-safe casting.

Return type:PySide2.QtCore.QSize

Implemented in subclasses to return the maximum size of this item.

Return type:PySide2.QtCore.int

Returns the minimum height this widget needs for the given width, w . The default implementation simply returns PySide2.QtWidgets.QLayoutItem.heightForWidth() (w ).

Return type:PySide2.QtCore.QSize

Implemented in subclasses to return the minimum size of this item.


Sets the alignment of this item to alignment .


Item alignment is only supported by PySide2.QtWidgets.QLayoutItem subclasses where it would have a visual effect. Except for PySide2.QtWidgets.QSpacerItem , which provides blank space for layouts, all public Qt classes that inherit PySide2.QtWidgets.QLayoutItem support item alignment.


Implemented in subclasses to set this item’s geometry to r .

Return type:PySide2.QtCore.QSize

Implemented in subclasses to return the preferred size of this item.

Return type:PySide2.QtWidgets.QSpacerItem

If this item is a PySide2.QtWidgets.QSpacerItem , it is returned as a PySide2.QtWidgets.QSpacerItem ; otherwise 0 is returned. This function provides type-safe casting.

Return type:PySide2.QtWidgets.QWidget

If this item manages a PySide2.QtWidgets.QWidget , returns that widget. Otherwise, nullptr is returned.