spacr.qt.widgets.flow

A left-to-right layout that wraps, and the widget that hosts one.

Lifted out of spacr.qt.screens.settings_model, where it was written for the settings panel’s chip strip, because a wrapping row is not a settings idea: the regression results header wants one too. Three combo boxes with minimum widths, a run name of unpredictable length and a QHBoxLayout do not fit in a narrow panel, and Qt’s answer to a box it cannot satisfy is to let the children overlap – measured at 577 px, where the second box started 48 px inside the first and the third ran 32 px off the panel.

Classes

FlowHost

The widget a FlowLayout lives in.

FlowLayout

A left-to-right layout that wraps onto a new line when it runs out.

Module Contents

class spacr.qt.widgets.flow.FlowHost(parent=None)[source]

Bases: PySide6.QtWidgets.QWidget

The widget a FlowLayout lives in.

Qt only consults a layout’s heightForWidth through the widget that owns it, and only when that widget’s size policy says its height depends on its width. Without this the strip reported a one-line height however many chips it held, and controls (thirty of them) drew off the edge of the settings column instead of wrapping.

Parameters:

parent – parent widget.

Create a widget that reports its height from its width.

Height-for-width is enabled explicitly: without it a wrapping layout’s extra lines are never given room and the last row is clipped.

Parameters:

parent – parent widget, or None.

hasHeightForWidth() → bool[source]

Yes – more width means fewer rows of chips.

heightForWidth(width: int) → int[source]

Height the chips need once wrapped into width.

Parameters:

width – available width in pixels, passed to the layout; without a layout the base class answers.

sizeHint() → PySide6.QtCore.QSize[source]

Preferred size at the current width, so the row grows as chips are added rather than clipping them.

class spacr.qt.widgets.flow.FlowLayout(parent=None, spacing: int = 4)[source]

Bases: PySide6.QtWidgets.QLayout

A left-to-right layout that wraps onto a new line when it runs out.

Chips have to wrap: controls ships thirty of them and a horizontal box would either clip them or force the settings panel wider than the window.

Parameters:
  • parent – parent widget.

  • spacing – pixels between chips, horizontally and vertically.

Create a layout that wraps its items onto new lines.

Parameters:
  • parent – the widget to lay out, or None.

  • spacing – gap between items, horizontally and vertically.

addItem(item) → None[source]

Append a layout item (Qt calls this for every added widget).

Parameters:

item – the QLayoutItem to append after the existing items.

count() → int[source]

Number of items in the layout.

expandingDirections()[source]

Never ask for extra space in either direction.

hasHeightForWidth() → bool[source]

Height depends on width – that is the whole point of wrapping.

heightForWidth(width: int) → int[source]

Height needed to lay the chips out inside width.

Parameters:

width – available width in pixels; the items are wrapped into it without being moved.

itemAt(index)[source]

Return the item at index, or None when out of range.

Parameters:

index – zero-based position of the item.

minimumSize() → PySide6.QtCore.QSize[source]

The largest single chip, plus margins.

setGeometry(rect) → None[source]

Place every chip inside rect.

Parameters:

rect – the QRect given to the layout; the items are wrapped and placed inside it.

sizeHint() → PySide6.QtCore.QSize[source]

Preferred size – the minimum, since the height is width-driven.

takeAt(index)[source]

Remove and return the item at index, or None.

Parameters:

index – zero-based position of the item to remove.