Skip to content

PythonQt.QtGui.QGraphicsLinearLayout

QGraphicsLinearLayout

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

The default orientation for a linear layout is Qt::Horizontal. You can choose a vertical orientation either by calling setOrientation(), or by passing Qt::Vertical to QGraphicsLinearLayout's constructor.

The most common way to use QGraphicsLinearLayout is to construct an object on the heap with no parent, add widgets and layouts by calling addItem(), and finally assign the layout to a widget by calling QGraphicsWidget::setLayout().

QGraphicsScene scene;
QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit);
QGraphicsWidget *pushButton = scene.addWidget(new QPushButton);

QGraphicsLinearLayout *layout = new QGraphicsLinearLayout;
layout->addItem(textEdit);
layout->addItem(pushButton);

QGraphicsWidget *form = new QGraphicsWidget;
form->setLayout(layout);
scene.addItem(form);

You can add widgets, layouts, stretches (addStretch(), insertStretch() or setStretchFactor()), and spacings (setItemSpacing()) to a linear layout. The layout takes ownership of the items. In some cases when the layout item also inherits from QGraphicsItem (such as QGraphicsWidget) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation of QGraphicsLayoutItem::setOwnedByLayout() how to handle this. You can access each item in the layout by calling count() and itemAt(). Calling removeAt() or removeItem() will remove an item from the layout, without destroying it.

Size Hints and Size Policies in QGraphicsLinearLayout

QGraphicsLinearLayout respects each item's size hints and size policies, and when the layout contains more space than the items can fill, each item is arranged according to the layout's alignment for that item. You can set an alignment for each item by calling setAlignment(), and check the alignment for any item by calling alignment(). By default, items are aligned to the top left.

Spacing within QGraphicsLinearLayout

Between the items, the layout distributes some space. The actual amount of space depends on the managed widget's current style, but the common spacing is 4. You can also set your own spacing by calling setSpacing(), and get the current spacing value by calling spacing(). If you want to configure individual spacing for your items, you can call setItemSpacing().

Stretch Factor in QGraphicsLinearLayout

You can assign a stretch factor to each item to control how much space it will get compared to the other items. By default, two identical widgets arranged in a linear layout will have the same size, but if the first widget has a stretch factor of 1 and the second widget has a stretch factor of 2, the first widget will get 1/3 of the available space, and the second will get 2/3.

QGraphicsLinearLayout calculates the distribution of sizes by adding up the stretch factors of all items, and then dividing the available space accordingly. The default stretch factor is 0 for all items; a factor of 0 means the item does not have any defined stretch factor; effectively this is the same as setting the stretch factor to 1. The stretch factor only applies to the available space in the lengthwise direction of the layout (following its orientation). If you want to control both the item's horizontal and vertical stretch, you can use QGraphicsGridLayout instead.

QGraphicsLinearLayout Compared to Other Layouts

QGraphicsLinearLayout is very similar to QVBoxLayout and QHBoxLayout, but in contrast to these classes, it is used to manage QGraphicsWidget and QGraphicsLayout instead of QWidget and QLayout.

Source: https://doc.qt.io/archives/qt-5.15/qgraphicslinearlayout.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 (shared captured text)
addChildLayoutItem function (self, layoutItem: Any) -> Any (shared captured text)
addItem function (self, item: Any) -> None This convenience function is equivalent to calling [insertItem](https://doc.qt.io/archives/qt-5.15/qgraphicslinearlayout.html#insertItem)(-1, item).
addStretch function (self, stretch: int) -> None This convenience function is equivalent to calling [insertStretch](https://doc.qt.io/archives/qt-5.15/qgraphicslinearlayout.html#insertStretch)(-1, stretch).
alignment function (self, item: Any) -> Any Returns the alignment for item.
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
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
dump function (self, indent: int) -> None
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)
insertItem function (self, index: int, item: Any) -> None X.insertItem(index, item)
insertStretch function (self, index: int, stretch: int) -> None X.insertStretch(index, stretch)
instantInvalidatePropagation function (self) -> bool X.instantInvalidatePropagation() -> bool (shared captured text)
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 (shared captured text)
isLayout function (self) -> bool X.isLayout() -> bool (shared captured text)
itemAt function (self, index: int) -> Any X.itemAt(index) -> PythonQt.QtGui.QGraphicsLayoutItem
itemSpacing function (self, index: int) -> float X.itemSpacing(index) -> float
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)
orientation function (self) -> Any Returns the layout orientation.
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 Reimplements: [QGraphicsLayout::removeAt](https://doc.qt.io/archives/qt-5.15/qgraphicslayout.html#removeAt)(int index).
removeItem function (self, item: Any) -> None Removes item from the layout without destroying it.
setAlignment function (self, item: Any, alignment: Any) -> None X.setAlignment(item, alignment)
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 (shared captured text)
setInstantInvalidatePropagation function (self, enable: Any) -> Any (shared captured text)
setItemSpacing function (self, index: int, spacing: float) -> None X.setItemSpacing(index, spacing)
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)
setOrientation function (self, orientation: Any) -> None Change the layout orientation to orientation.
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)
setSpacing function (self, spacing: float) -> None Sets the layout's spacing to spacing.
setStretchFactor function (self, item: Any, stretch: int) -> None X.setStretchFactor(item, stretch)
sizeHint function (self, which: Any, constraint: Any) -> Any X.sizeHint(which, constraint) -> PythonQt.QtCore.QSizeF
sizePolicy function (self) -> Any X.sizePolicy() -> PythonQt.QtGui.QSizePolicy (shared captured text)
spacing function (self) -> float X.spacing() -> float
stretchFactor function (self, item: Any) -> int X.stretchFactor(item) -> int
updateGeometry function (self) -> Any (shared captured text)
widgetEvent function (self, e: Any) -> Any (shared captured text)