Skip to content

QFlowLayout

A QLayout that places its items in a row, left to right, and wraps them onto a new row when there's no more room, like words in a paragraph. Resizing the widget rearranges them.

QFlowLayout QFlowLayout
from qtpy.QtWidgets import QApplication, QPushButton, QWidget

from superqt import QFlowLayout

app = QApplication([])

wdg = QWidget()

layout = QFlowLayout(wdg)
layout.addWidget(QPushButton("Short"))
layout.addWidget(QPushButton("Longer"))
layout.addWidget(QPushButton("Different text"))
layout.addWidget(QPushButton("More text"))
layout.addWidget(QPushButton("Even longer button text"))

wdg.setWindowTitle("Flow Layout")
wdg.show()

app.exec()

QFlowLayout

QFlowLayout(parent: QWidget | None = None)

Layout that handles different window sizes.

The widget placement changes depending on the width of the application window.

Code translated from C++ at: https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/layouts/flowlayout

described at: https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html

See also: https://doc.qt.io/qt-6/layout.html

Parameters:

  • parent (QWidget, default: None ) –

    The parent widget, by default None

Subclass of QLayout

QFlowLayout inherits all of QLayout's methods, signals, and properties. Only those that superqt adds or changes are listed here.

Methods

Layout that handles different window sizes.

The widget placement changes depending on the width of the application window.

Code translated from C++ at: https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/layouts/flowlayout

described at: https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html

See also: https://doc.qt.io/qt-6/layout.html

Parameters:

  • parent (QWidget, default: None ) –

    The parent widget, by default None

addItem

addItem(item: QLayoutItem | None) -> None

Add an item to the layout.

count

count() -> int

Return the number of items in the layout.

expandingDirections

expandingDirections() -> Orientation

Return the expanding directions.

These are the Qt::Orientations in which the layout can make use of more space than its sizeHint().

hasHeightForWidth

hasHeightForWidth() -> bool

Return whether the layout handles height for width.

heightForWidth

heightForWidth(width: int) -> int

Return the height for a given width.

heightForWidth() passes the width on to _doLayout() which in turn uses the width as an argument for the layout rect, i.e., the bounds in which the items are laid out. This rect does not include the layout margin().

horizontalSpacing

horizontalSpacing() -> int

Return the horizontal spacing.

itemAt

itemAt(index: int) -> QLayoutItem | None

Return the item at the given index, or None if the index is out of range.

minimumSize

minimumSize() -> QSize

Return the minimum size of the layout.

setGeometry

setGeometry(rect: QRect) -> None

Set the geometry of the layout.

This triggers a re-layout of the items.

setHorizontalSpacing

setHorizontalSpacing(space: int | None) -> None

Set the horizontal spacing.

If None or -1, the spacing is set to the default value based on the style of the parent widget.

setVerticalSpacing

setVerticalSpacing(space: int | None) -> None

Set the vertical spacing.

If None or -1, the spacing is set to the default value based on the style of the parent widget.

takeAt

takeAt(index: int) -> QLayoutItem | None

Remove and return the item at the given index. Or return None.

verticalSpacing

verticalSpacing() -> int

Return the vertical spacing.