feat: add QFlowLayout, for variable width widgets (#271)

* feat: add QLayout

* add to docs
This commit is contained in:
Talley Lambert
2025-01-05 16:17:27 -05:00
committed by GitHub
parent 6a7a731c5d
commit 3ff2d7ccce
7 changed files with 268 additions and 1 deletions

27
tests/test_flow_layout.py Normal file
View File

@@ -0,0 +1,27 @@
from typing import Any
from qtpy.QtWidgets import QPushButton, QWidget
from superqt import QFlowLayout
def test_flow_layout(qtbot: Any) -> None:
wdg = QWidget()
qtbot.addWidget(wdg)
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()
assert layout.expandingDirections()
assert layout.heightForWidth(200) > layout.heightForWidth(400)
assert layout.count() == 5
assert layout.itemAt(0).widget().text() == "Short"
layout.takeAt(0)
assert layout.count() == 4