Skip to content

PythonQt.QtGui.QGraphicsAnchorLayout

QGraphicsAnchorLayout

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

The anchor layout allows developers to specify how widgets should be placed relative to each other, and to the layout itself. The specification is made by adding anchors to the layout by calling addAnchor(), addAnchors() or addCornerAnchors().

Existing anchors in the layout can be accessed with the anchor() function. Items that are anchored are automatically added to the layout, and if items are removed, all their anchors will be automatically removed.

Using an anchor layout to align simple colored
widgets.

Anchors are always set up between edges of an item, where the "center" is also considered to be an edge. Consider the following example:

layout->addAnchor(b, Qt::AnchorLeft, a, Qt::AnchorRight);
layout->addAnchor(b, Qt::AnchorTop, a, Qt::AnchorBottom);

Here, the right edge of item a is anchored to the left edge of item b and the bottom edge of item a is anchored to the top edge of item b, with the result that item b will be placed diagonally to the right and below item b.

The addCornerAnchors() function provides a simpler way of anchoring the corners of two widgets than the two individual calls to addAnchor() shown in the code above. Here, we see how a widget can be anchored to the top-left corner of the enclosing layout:

layout->addCornerAnchors(a, Qt::TopLeftCorner, layout, Qt::TopLeftCorner);

In cases where anchors are used to match the widths or heights of widgets, it is convenient to use the addAnchors() function. As with the other functions for specifying anchors, it can also be used to anchor a widget to a layout.

Size Hints and Size Policies in an Anchor Layout

QGraphicsAnchorLayout respects each item's size hints and size policies. Note that there are some properties of QSizePolicy that are not respected.

Spacing within an Anchor Layout

The layout may distribute some space between the items. If the spacing has not been explicitly specified, the actual amount of space will usually be 0.

However, if the first edge is the opposite of the second edge (e.g., the right edge of the first widget is anchored to the left edge of the second widget), the size of the anchor will be queried from the style through a pixel metric: PM_LayoutHorizontalSpacing for horizontal anchors and PM_LayoutVerticalSpacing for vertical anchors.

If the spacing is negative, the items will overlap to some extent.

Known Issues

There are some features that QGraphicsAnchorLayout currently does not support. This might change in the future, so avoid using these features if you want to avoid any future regressions in behaviour:

Source: https://doc.qt.io/archives/qt-5.15/qgraphicsanchorlayout.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) -> Any
addAnchor function (self, firstItem: Any, firstEdge: Any, secondItem: Any, secondEdge: Any) -> Any X.addAnchor(firstItem, firstEdge, secondItem, secondEdge) -> PythonQt.QtGui.QGraphicsAnchor
addAnchors function (self, firstItem: Any, secondItem: Any, orientations: Any) -> None X.addAnchors(firstItem, secondItem, orientations)
addChildLayoutItem function (self, layoutItem: Any) -> Any
addCornerAnchors function (self, firstItem: Any, firstCorner: Any, secondItem: Any, secondCorner: Any) -> None X.addCornerAnchors(firstItem, firstCorner, secondItem, secondCorner)
anchor function (self, firstItem: Any, firstEdge: Any, secondItem: Any, secondEdge: Any) -> Any X.anchor(firstItem, firstEdge, secondItem, secondEdge) -> PythonQt.QtGui.QGraphicsAnchor
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
count function (self) -> int X.count() -> int
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
geometry function (self) -> Any X.geometry() -> PythonQt.QtCore.QRectF
getContentsMargins function (self, left: Any, top: Any, right: Any, bottom: Any) -> Any X.getContentsMargins(left, top, right, bottom)
graphicsItem function (self) -> Any X.graphicsItem() -> PythonQt.QtGui.QGraphicsItem
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
horizontalSpacing function (self) -> float X.horizontalSpacing() -> float
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
invalidate function (self) -> None Reimplements: [QGraphicsLayout::invalidate](https://doc.qt.io/archives/qt-5.15/qgraphicslayout.html#invalidate)().
isActivated function (self) -> bool X.isActivated() -> bool
isLayout function (self) -> bool X.isLayout() -> bool
itemAt function (self, index: int) -> Any X.itemAt(index) -> PythonQt.QtGui.QGraphicsLayoutItem
maximumHeight function (self) -> float X.maximumHeight() -> float
maximumSize function (self) -> Any X.maximumSize() -> PythonQt.QtCore.QSizeF
maximumWidth function (self) -> float X.maximumWidth() -> float
minimumHeight function (self) -> float X.minimumHeight() -> float
minimumSize function (self) -> Any X.minimumSize() -> PythonQt.QtCore.QSizeF
minimumWidth function (self) -> float X.minimumWidth() -> float
ownedByLayout function (self) -> bool X.ownedByLayout() -> bool
parentLayoutItem function (self) -> Any X.parentLayoutItem() -> PythonQt.QtGui.QGraphicsLayoutItem
preferredHeight function (self) -> float X.preferredHeight() -> float
preferredSize function (self) -> Any X.preferredSize() -> PythonQt.QtCore.QSizeF
preferredWidth function (self) -> float X.preferredWidth() -> float
removeAt function (self, index: int) -> None Reimplements: [QGraphicsLayout::removeAt](https://doc.qt.io/archives/qt-5.15/qgraphicslayout.html#removeAt)(int index).
setContentsMargins function (self, left: Any, top: Any, right: Any, bottom: Any) -> Any X.setContentsMargins(left, top, right, bottom) (shared captured text)
setGeometry function (self, rect: Any) -> None Reimplements: [QGraphicsLayoutItem::setGeometry](https://doc.qt.io/archives/qt-5.15/qgraphicslayoutitem.html#setGeometry)(const QRectF \&rect).
setGraphicsItem function (self, item: Any) -> Any
setHorizontalSpacing function (self, spacing: float) -> None Sets the default horizontal spacing for the anchor layout to spacing.
setInstantInvalidatePropagation function (self, enable: Any) -> Any
setMaximumHeight function (self, height: Any) -> Any
setMaximumSize function (self, w: Any, h: Any) -> Any X.setMaximumSize(w, h)
setMaximumWidth function (self, width: Any) -> Any
setMinimumHeight function (self, height: Any) -> Any
setMinimumSize function (self, w: Any, h: Any) -> Any X.setMinimumSize(w, h)
setMinimumWidth function (self, width: Any) -> Any
setOwnedByLayout function (self, ownedByLayout: Any) -> Any
setParentLayoutItem function (self, parent: Any) -> Any
setPreferredHeight function (self, height: Any) -> Any
setPreferredSize function (self, w: Any, h: Any) -> Any X.setPreferredSize(w, h)
setPreferredWidth function (self, width: Any) -> Any
setSizePolicy function (self, hPolicy: Any, vPolicy: Any, controlType: Any) -> Any X.setSizePolicy(hPolicy, vPolicy, controlType)
setSpacing function (self, spacing: float) -> None Sets the default horizontal and the default vertical spacing for the anchor layout to spacing.
setVerticalSpacing function (self, spacing: float) -> None Sets the default vertical spacing for the anchor layout to spacing.
sizeHint function (self, which: Any, constraint: Any) -> Any X.sizeHint(which, constraint) -> PythonQt.QtCore.QSizeF
sizePolicy function (self) -> Any X.sizePolicy() -> PythonQt.QtGui.QSizePolicy
updateGeometry function (self) -> Any (shared captured text)
verticalSpacing function (self) -> float X.verticalSpacing() -> float
widgetEvent function (self, e: Any) -> Any