Skip to content

PythonQt.Qt.QGraphicsLayoutItem

QGraphicsLayoutItem

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QGraphicsLayoutItem is an abstract class that defines a set of virtual functions describing sizes, size policies, and size hints for any object arranged by QGraphicsLayout. The API contains functions relevant for both the item itself and for the user of the item as most of QGraphicsLayoutItem's functions are also part of the subclass' public API.

In most cases, existing layout-aware classes such as QGraphicsWidget and QGraphicsLayout already provide the functionality you require. However, subclassing these classes will enable you to create both graphical elements that work well with layouts (QGraphicsWidget) or custom layouts (QGraphicsLayout).

Subclassing QGraphicsLayoutItem

If you create a subclass of QGraphicsLayoutItem and reimplement its virtual functions, you will enable the layout to resize and position your item along with other QGraphicsLayoutItems including QGraphicsWidget and QGraphicsLayout.

You can start by reimplementing important functions: the protected sizeHint() function, as well as the public setGeometry() function. If you want your items to be aware of immediate geometry changes, you can also reimplement updateGeometry().

The geometry, size hint, and size policy affect the item's size and position. Calling setGeometry() will always resize and reposition the item immediately. Normally, this function is called by QGraphicsLayout after the layout has been activated, but it can also be called by the item's user at any time.

The sizeHint() function returns the item' minimum, preferred and maximum size hints. You can override these properties by calling setMinimumSize(), setPreferredSize() or setMaximumSize(). You can also use functions such as setMinimumWidth() or setMaximumHeight() to set only the width or height component if desired.

The effectiveSizeHint() function, on the other hand, returns a size hint for any given Qt::SizeHint, and guarantees that the returned size is bound to the minimum and maximum sizes and size hints. You can set the item's vertical and horizontal size policy by calling setSizePolicy(). The sizePolicy property is used by the layout system to describe how this item prefers to grow or shrink.

Nesting QGraphicsLayoutItems

QGraphicsLayoutItems can be nested within other QGraphicsLayoutItems, similar to layouts that can contain sublayouts. This is done either by passing a QGraphicsLayoutItem pointer to QGraphicsLayoutItem's protected constructor, or by calling setParentLayoutItem(). The parentLayoutItem() function returns a pointer to the item's layoutItem parent. If the item's parent is nullptr or if the parent does not inherit from QGraphicsItem, the parentLayoutItem() function then returns nullptr. isLayout() returns true if the QGraphicsLayoutItem subclass is itself a layout, or false otherwise.

Qt uses QGraphicsLayoutItem to provide layout functionality in the Graphics View Framework, but in the future its use may spread throughout Qt itself.

Source: https://doc.qt.io/archives/qt-5.15/qgraphicslayoutitem.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)
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)
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)
isLayout function (self) -> bool X.isLayout() -> bool (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)
setGeometry function (self, rect: Any) -> None This virtual function sets the geometry of the [QGraphicsLayoutItem](https://doc.qt.io/archives/qt-5.15/qgraphicslayoutitem.html) to rect, which is in parent coordinates (e.g., the top-left corner… (shared captured text)
setGraphicsItem function (self, item: Any) -> None If the [QGraphicsLayoutItem](https://doc.qt.io/archives/qt-5.15/qgraphicslayoutitem.html) represents a [QGraphicsItem](https://doc.qt.io/archives/qt-5.15/qgraphicsitem.html), and it wants to take… (shared captured text)
setMaximumHeight function (self, height: float) -> None Sets the maximum height to height. (shared captured text)
setMaximumSize function (self, w: Any, h: Any) -> None X.setMaximumSize(w, h) (shared captured text)
setMaximumWidth function (self, width: float) -> None Sets the maximum width to width. (shared captured text)
setMinimumHeight function (self, height: float) -> None Sets the minimum height to height. (shared captured text)
setMinimumSize function (self, w: Any, h: Any) -> None X.setMinimumSize(w, h) (shared captured text)
setMinimumWidth function (self, width: float) -> None Sets the minimum width to width. (shared captured text)
setOwnedByLayout function (self, ownedByLayout: bool) -> None Sets whether a layout should delete this item in its destructor or not. ownership must be true to in order for the layout to delete it. (shared captured text)
setParentLayoutItem function (self, parent: Any) -> None Sets the parent of this [QGraphicsLayoutItem](https://doc.qt.io/archives/qt-5.15/qgraphicslayoutitem.html) to parent. (shared captured text)
setPreferredHeight function (self, height: float) -> None Sets the preferred height to height. (shared captured text)
setPreferredSize function (self, w: Any, h: Any) -> None X.setPreferredSize(w, h) (shared captured text)
setPreferredWidth function (self, width: float) -> None Sets the preferred width to width. (shared captured text)
setSizePolicy function (self, hPolicy: Any, vPolicy: Any, controlType: Any) -> None 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 This virtual function discards any cached size hint information. (shared captured text)