Gtk.FlowBox¶
class — extends Widget, Accessible, Buildable, ConstraintTarget, Orientable
Puts child widgets in a reflowing grid.
<picture> <source srcset="flow-box-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkFlowBox" src="flow-box.png"> </picture>
For instance, with the horizontal orientation, the widgets will be arranged from left to right, starting a new row under the previous row when necessary. Reducing the width in this case will require more rows, so a larger height will be requested.
Likewise, with the vertical orientation, the widgets will be arranged from top to bottom, starting a new column to the right when necessary. Reducing the height will require more columns, so a larger width will be requested.
The size request of a GtkFlowBox alone may not be what you expect;
if you need to be able to shrink it along both axes and dynamically
reflow its children, you may have to wrap it in a GtkScrolledWindow
to enable that.
The children of a GtkFlowBox can be dynamically sorted and filtered.
Although a GtkFlowBox must have only GtkFlowBoxChild children, you
can add any kind of widget to it via FlowBox.insert, and a
GtkFlowBoxChild widget will automatically be inserted between the box
and the widget.
Also see ListBox.
Shortcuts and Gestures¶
The following signals have default keybindings:
CSS nodes¶
GtkFlowBox uses a single CSS node with name flowbox. GtkFlowBoxChild
uses a single CSS node with name flowboxchild. For rubberband selection,
a subnode with name rubberband is used.
Accessibility¶
GtkFlowBox uses the AccessibleRole.grid role, and GtkFlowBoxChild
uses the AccessibleRole.grid_cell role.
Constructors¶
new¶
Creates a GtkFlowBox.
Methods¶
append¶
Adds child to the end of self.
If a sort function is set, the widget will actually be inserted at the calculated position.
See also: FlowBox.insert.
Parameters:
child— theGtkWidgetto add
bind_model¶
def bind_model(self, model: Gio.ListModel | None, create_widget_func: FlowBoxCreateWidgetFunc) -> None
Binds model to box.
If box was already bound to a model, that previous binding is
destroyed.
The contents of box are cleared and then filled with widgets that
represent items from model. box is updated whenever model changes.
If model is None, box is left empty.
It is undefined to add or remove widgets directly (for example, with
FlowBox.insert) while box is bound to a model.
Note that using a model is incompatible with the filtering and sorting
functionality in GtkFlowBox. When using a model, filtering and sorting
should be implemented by the model.
Parameters:
model— theGListModelto be bound toboxcreate_widget_func— a function that creates widgets for items
get_activate_on_single_click¶
Returns whether children activate on single clicks.
get_child_at_index¶
Gets the nth child in the box.
Parameters:
idx— the position of the child
get_child_at_pos¶
Gets the child in the (x, y) position.
Both x and y are assumed to be relative to the origin of box.
Parameters:
x— the x coordinate of the childy— the y coordinate of the child
get_column_spacing¶
Gets the horizontal spacing.
get_homogeneous¶
Returns whether the box is homogeneous.
get_max_children_per_line¶
Gets the maximum number of children per line.
get_min_children_per_line¶
Gets the minimum number of children per line.
get_row_spacing¶
Gets the vertical spacing.
get_selected_children¶
Creates a list of all selected children.
get_selection_mode¶
Gets the selection mode of box.
insert¶
Inserts the widget into box at position.
If a sort function is set, the widget will actually be inserted at the calculated position.
If position is -1, or larger than the total number of children
in the box, then the widget will be appended to the end.
Parameters:
widget— theGtkWidgetto addposition— the position to insertchildin
invalidate_filter¶
Updates the filtering for all children.
Call this function when the result of the filter
function on the box is changed due to an external
factor. For instance, this would be used if the
filter function just looked for a specific search
term, and the entry with the string has changed.
invalidate_sort¶
Updates the sorting for all children.
Call this when the result of the sort function on
box is changed due to an external factor.
prepend¶
Adds child to the start of self.
If a sort function is set, the widget will actually be inserted at the calculated position.
See also: FlowBox.insert.
Parameters:
child— theGtkWidgetto add
remove¶
Removes a child from box.
Parameters:
widget— the child widget to remove
remove_all¶
Removes all children from box.
This function does nothing if box is backed by a model.
select_all¶
Select all children of box, if the selection
mode allows it.
select_child¶
Selects a single child of box, if the selection
mode allows it.
Parameters:
child— a child ofbox
selected_foreach¶
Calls a function for each selected child.
Note that the selection cannot be modified from within this function.
Parameters:
func— the function to call for each selected child
set_activate_on_single_click¶
If single is True, children will be activated when you click
on them, otherwise you need to double-click.
Parameters:
single—Trueto emit child-activated on a single click
set_column_spacing¶
Sets the horizontal space to add between children.
Parameters:
spacing— the spacing to use
set_filter_func¶
By setting a filter function on the box one can decide dynamically
which of the children to show.
For instance, to implement a search function that only shows the children matching the search terms.
The filter_func will be called for each child after the call, and
it will continue to be called each time a child changes (via
FlowBoxChild.changed) or when
FlowBox.invalidate_filter is called.
Note that using a filter function is incompatible with using a model
(see FlowBox.bind_model).
Parameters:
filter_func— callback that lets you filter which children to show
set_hadjustment¶
Hooks up an adjustment to focus handling in box.
The adjustment is also used for autoscrolling during
rubberband selection. See ScrolledWindow.get_hadjustment
for a typical way of obtaining the adjustment, and
FlowBox.set_vadjustment for setting the vertical
adjustment.
The adjustments have to be in pixel units and in the same coordinate system as the allocation for immediate children of the box.
Parameters:
adjustment— an adjustment which should be adjusted when the focus is moved among the descendents ofcontainer
set_homogeneous¶
Sets whether or not all children of box are given
equal space in the box.
Parameters:
homogeneous—Trueto create equal allotments,Falsefor variable allotments
set_max_children_per_line¶
Sets the maximum number of children to request and
allocate space for in box’s orientation.
Setting the maximum number of children per line
limits the overall natural size request to be no more
than n_children children long in the given orientation.
Parameters:
n_children— the maximum number of children per line
set_min_children_per_line¶
Sets the minimum number of children to line up
in box’s orientation before flowing.
Parameters:
n_children— the minimum number of children per line
set_row_spacing¶
Sets the vertical space to add between children.
Parameters:
spacing— the spacing to use
set_selection_mode¶
Sets how selection works in box.
Parameters:
mode— the new selection mode
set_sort_func¶
By setting a sort function on the box, one can dynamically
reorder the children of the box, based on the contents of
the children.
The sort_func will be called for each child after the call,
and will continue to be called each time a child changes (via
FlowBoxChild.changed) and when
FlowBox.invalidate_sort is called.
Note that using a sort function is incompatible with using a model
(see FlowBox.bind_model).
Parameters:
sort_func— the sort function
set_vadjustment¶
Hooks up an adjustment to focus handling in box.
The adjustment is also used for autoscrolling during
rubberband selection. See ScrolledWindow.get_vadjustment
for a typical way of obtaining the adjustment, and
FlowBox.set_hadjustment for setting the horizontal
adjustment.
The adjustments have to be in pixel units and in the same coordinate system as the allocation for immediate children of the box.
Parameters:
adjustment— an adjustment which should be adjusted when the focus is moved among the descendents ofcontainer
unselect_all¶
Unselect all children of box, if the selection
mode allows it.
unselect_child¶
Unselects a single child of box, if the selection
mode allows it.
Parameters:
child— a child ofbox
Properties¶
accept_unpaired_release¶
Whether to accept unpaired release events.
activate_on_single_click¶
Determines whether children can be activated with a single click, or require a double-click.
column_spacing¶
The amount of horizontal space between two children.
homogeneous¶
Determines whether all children should be allocated the same size.
max_children_per_line¶
The maximum amount of children to request space for consecutively in the given orientation.
min_children_per_line¶
The minimum number of children to allocate consecutively in the given orientation.
Setting the minimum children per line ensures that a reasonably small height will be requested for the overall minimum width of the box.
row_spacing¶
The amount of vertical space between two children.
selection_mode¶
The selection mode used by the flow box.
Signals¶
activate-cursor-child¶
Emitted when the user activates the box.
This is a keybinding signal.
child-activated¶
Emitted when a child has been activated by the user.
move-cursor¶
Emitted when the user initiates a cursor movement.
This is a keybinding signal. Applications should not connect to it, but may emit it with g_signal_emit_by_name() if they need to control the cursor programmatically.
The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without the Shift modifier does not. There are too many key combinations to list them all here.
- <kbd>←</kbd>, <kbd>→</kbd>, <kbd>↑</kbd>, <kbd>↓</kbd> move by individual children
- <kbd>Home</kbd>, <kbd>End</kbd> move to the ends of the box
- <kbd>PgUp</kbd>, <kbd>PgDn</kbd> move vertically by pages
select-all¶
Emitted to select all children of the box, if the selection mode permits it.
This is a keybinding signal.
The default bindings for this signal is <kbd>Ctrl</kbd>-<kbd>a</kbd>.
selected-children-changed¶
Emitted when the set of selected children changes.
Use FlowBox.selected_foreach or
FlowBox.get_selected_children to obtain the
selected children.
toggle-cursor-child¶
Emitted to toggle the selection of the child that has the focus.
This is a keybinding signal.
The default binding for this signal is <kbd>Ctrl</kbd>-<kbd>Space</kbd>.
unselect-all¶
Emitted to unselect all children of the box, if the selection mode permits it.
This is a keybinding signal.
The default bindings for this signal is <kbd>Ctrl</kbd>-<kbd>Shift</kbd>-<kbd>a</kbd>.