Skip to content

PythonQt.Qt.QGraphicsLayout

QGraphicsLayout

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QGraphicsLayout is an abstract class that defines a virtual API for arranging QGraphicsWidget children and other QGraphicsLayoutItem objects for a QGraphicsWidget. QGraphicsWidget assigns responsibility to a QGraphicsLayout through QGraphicsWidget::setLayout(). As the widget is resized, the layout will automatically arrange the widget's children. QGraphicsLayout inherits QGraphicsLayoutItem, so, it can be managed by any layout, including its own subclasses.

Writing a Custom Layout

You can use QGraphicsLayout as a base to write your own custom layout (e.g., a flowlayout), but it is more common to use one of its subclasses instead - QGraphicsLinearLayout or QGraphicsGridLayout. When creating a custom layout, the following functions must be reimplemented as a bare minimum:

Function Description
QGraphicsLayoutItem::setGeometry() Notifies you when the geometry of the layout is set. You can store the geometry in your own layout class in a reimplementation of this function.
QGraphicsLayoutItem::sizeHint() Returns the layout's size hints.
QGraphicsLayout::count() Returns the number of items in your layout.
QGraphicsLayout::itemAt() Returns a pointer to an item in your layout.
QGraphicsLayout::removeAt() Removes an item from your layout without destroying it.

For more details on how to implement each function, refer to the individual function documentation.

Each layout defines its own API for arranging widgets and layout items. For example, with a grid layout, you require a row and a column index with optional row and column spans, alignment, spacing, and more. A linear layout, however, requires a single row or column index to position its items. For a grid layout, the order of insertion does not affect the layout in any way, but for a linear layout, the order is essential. When writing your own layout subclass, you are free to choose the API that best suits your layout.

QGraphicsLayout provides the addChildLayoutItem() convenience function to add layout items to a custom layout. The function will automatically reparent graphics items, if required.

Activating the Layout

When the layout's geometry changes, QGraphicsLayout immediately rearranges all of its managed items by calling setGeometry() on each item. This rearrangement is called activating the layout.

QGraphicsLayout updates its own geometry to match the contentsRect() of the QGraphicsLayoutItem it is managing. Thus, it will automatically rearrange all its items when the widget is resized. QGraphicsLayout caches the sizes of all its managed items to avoid calling setGeometry() too often.

Note: A QGraphicsLayout will have the same geometry as the contentsRect() of the widget (not the layout) it is assigned to.

Activating the Layout Implicitly

The layout can be activated implicitly using one of two ways: by calling activate() or by calling invalidate(). Calling activate() activates the layout immediately. In contrast, calling invalidate() is delayed, as it posts a LayoutRequest event to the managed widget. Due to event compression, the activate() will only be called once after control has returned to the event loop. This is referred to as invalidating the layout. Invalidating the layout also invalidates any cached information. Also, the invalidate() function is a virtual function. So, you can invalidate your own cache in a subclass of QGraphicsLayout by reimplementing this function.

Event Handling

QGraphicsLayout listens to events for the widget it manages through the virtual widgetEvent() event handler. When the layout is assigned to a widget, all events delivered to the widget are first processed by widgetEvent(). This allows the layout to be aware of any relevant state changes on the widget such as visibility changes or layout direction changes.

Margin Handling

The margins of a QGraphicsLayout can be modified by reimplementing setContentsMargins() and getContentsMargins().

Source: https://doc.qt.io/archives/qt-5.15/qgraphicslayout.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
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
activate function (self) -> None Activates the layout, causing all items in the layout to be immediately rearranged. (shared captured text)
addChildLayoutItem function (self, layoutItem: Any) -> None This function is a convenience function provided for custom layouts, and will go through all items in the layout and reparent their graphics items to the closest… (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
contentsRect function (self) -> Any X.contentsRect() -> PythonQt.QtCore.QRectF (shared captured text)
count function (self) -> int X.count() -> int (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
effectiveSizeHint function (self, which: Any, constraint: Any) -> Any X.effectiveSizeHint(which, constraint) -> PythonQt.QtCore.QSizeF (shared captured text)
geometry function (self) -> Any X.geometry() -> PythonQt.QtCore.QRectF (shared captured text)
getContentsMargins function (self, left: Any, top: Any, right: Any, bottom: Any) -> Any X.getContentsMargins(left, top, right, bottom) (shared captured text)
graphicsItem function (self) -> Any X.graphicsItem() -> PythonQt.QtGui.QGraphicsItem (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
instantInvalidatePropagation function (self) -> bool X.instantInvalidatePropagation() -> bool (shared captured text)
invalidate function (self) -> None Clears any cached geometry and size hint information in the layout, and posts a [LayoutRequest](https://doc.qt.io/archives/qt-5.15/qevent.html#Type-enum) event to the managed parent… (shared captured text)
isActivated function (self) -> bool X.isActivated() -> bool (shared captured text)
isLayout function (self) -> bool X.isLayout() -> bool (shared captured text)
itemAt function (self, i: int) -> Any X.itemAt(i) -> PythonQt.QtGui.QGraphicsLayoutItem (shared captured text)
maximumHeight function (self) -> float X.maximumHeight() -> float (shared captured text)
maximumSize function (self) -> Any X.maximumSize() -> PythonQt.QtCore.QSizeF (shared captured text)
maximumWidth function (self) -> float X.maximumWidth() -> float (shared captured text)
minimumHeight function (self) -> float X.minimumHeight() -> float (shared captured text)
minimumSize function (self) -> Any X.minimumSize() -> PythonQt.QtCore.QSizeF (shared captured text)
minimumWidth function (self) -> float X.minimumWidth() -> float (shared captured text)
ownedByLayout function (self) -> bool X.ownedByLayout() -> bool (shared captured text)
parentLayoutItem function (self) -> Any X.parentLayoutItem() -> PythonQt.QtGui.QGraphicsLayoutItem (shared captured text)
preferredHeight function (self) -> float X.preferredHeight() -> float (shared captured text)
preferredSize function (self) -> Any X.preferredSize() -> PythonQt.QtCore.QSizeF (shared captured text)
preferredWidth function (self) -> float X.preferredWidth() -> float (shared captured text)
removeAt function (self, index: int) -> None This pure virtual function must be reimplemented in a subclass of [QGraphicsLayout](https://doc.qt.io/archives/qt-5.15/graphicsview.html#qgraphicslayout) to remove the item at index. (shared captured text)
setContentsMargins function (self, left: float, top: float, right: float, bottom: float) -> None X.setContentsMargins(left, top, right, bottom) (shared captured text)
setGeometry function (self, rect: Any) -> Any (shared captured text)
setGraphicsItem function (self, item: Any) -> Any (shared captured text)
setInstantInvalidatePropagation function (self, enable: bool) -> None (shared captured text)
setMaximumHeight function (self, height: Any) -> Any (shared captured text)
setMaximumSize function (self, w: Any, h: Any) -> Any X.setMaximumSize(w, h) (shared captured text)
setMaximumWidth function (self, width: Any) -> Any (shared captured text)
setMinimumHeight function (self, height: Any) -> Any (shared captured text)
setMinimumSize function (self, w: Any, h: Any) -> Any X.setMinimumSize(w, h) (shared captured text)
setMinimumWidth function (self, width: Any) -> Any (shared captured text)
setOwnedByLayout function (self, ownedByLayout: Any) -> Any (shared captured text)
setParentLayoutItem function (self, parent: Any) -> Any (shared captured text)
setPreferredHeight function (self, height: Any) -> Any (shared captured text)
setPreferredSize function (self, w: Any, h: Any) -> Any X.setPreferredSize(w, h) (shared captured text)
setPreferredWidth function (self, width: Any) -> Any (shared captured text)
setSizePolicy function (self, hPolicy: Any, vPolicy: Any, controlType: Any) -> Any X.setSizePolicy(hPolicy, vPolicy, controlType) (shared captured text)
sizeHint function (self, which: Any, constraint: Any) -> Any X.sizeHint(which, constraint) -> PythonQt.QtCore.QSizeF (shared captured text)
sizePolicy function (self) -> Any X.sizePolicy() -> PythonQt.QtGui.QSizePolicy (shared captured text)
updateGeometry function (self) -> None Reimplements: [QGraphicsLayoutItem::updateGeometry](https://doc.qt.io/archives/qt-5.15/qgraphicslayoutitem.html#updateGeometry)(). (shared captured text)
widgetEvent function (self, e: Any) -> None This virtual event handler receives all events for the managed widget. (shared captured text)