DAFlowLayout¶
DAFlowLayout is a flow layout that arranges child widgets left-to-right, top-to-bottom, automatically wrapping to the next line when the width is exceeded. The trailing item can be set to expand and fill the remaining space.
Preview¶

Ten buttons automatically form two rows at this width. Narrow the window further and they keep wrapping; heightForWidth() reports the matching height so the container can grow.
Key Features¶
- ✅ Auto-wrap: Child widgets automatically wrap to the next line when exceeding container width
- ✅ Trailing expansion:
setTrailingExpanding(true)makes the last item fill the remaining width - ✅ heightForWidth support: Dynamically calculates required height based on width
- ✅ Independently usable: Can be used in any scenario requiring flow arrangement
Usage¶
1. Basic Usage¶
1 2 3 4 5 6 7 8 9 10 | |
2. Trailing Expansion Mode¶
In DAChipsEdit, the input field is the trailing item and needs to fill the remaining width:
1 2 3 4 5 6 7 8 9 10 11 | |
How It Works
When trailingExpanding is true, the layout calculates the remaining width on each line and sets the trailing item's width to fill it. If the trailing item is alone on its line, it occupies the full line width.
3. Spacing and Margins¶
1 2 3 4 5 6 7 | |
Core Properties & Methods¶
| Method | Description |
|---|---|
setTrailingExpanding(bool) |
Enable/disable trailing item expansion |
trailingExpanding() |
Get trailing expansion state |
setSpacing(int) |
Set widget spacing |
heightForWidth(int) |
Calculate required height for a given width |