On top of this, the "listitem.expand", "listitem.collapse" and
"listitem.toggle-expand" actions are provided to allow adding custom
UI for managing expanded state.
It is important to mention that you want to set the
gtk.list_item.ListItem.gboolean property to FALSE when using this
widget, as you want the keyboard focus to be in the treexpander, and not
inside the list to make use of the keybindings.
gtk.tree_expander.TreeExpander can be modified with properties such as
property@Gtk.TreeExpander:indent-for-icon,
property@Gtk.TreeExpander:indent-for-depth, and
property@Gtk.TreeExpander:hide-expander to achieve a different appearance.
This can even be done to influence individual rows, for example by binding
the property@Gtk.TreeExpander:hide-expander property to the item count of
the model of the treelistrow, to hide the expander for rows without children,
even if the row is expandable.
gtk.tree_expander.TreeExpander has zero or one CSS nodes with the name "expander" that
should display the expander icon. The node will be :checked when it
is expanded. If the node is not expandable, an "indent" node will be
displayed instead.
For every level of depth, another "indent" node is prepended.
gtk.tree_expander.TreeExpander is a widget that provides an expander for a list.
It is typically placed as a bottommost child into a gtk.list_view.ListView to allow users to expand and collapse children in a list with a gtk.tree_list_model.TreeListModel. gtk.tree_expander.TreeExpander provides the common UI elements, gestures and keybindings for this purpose.
On top of this, the "listitem.expand", "listitem.collapse" and "listitem.toggle-expand" actions are provided to allow adding custom UI for managing expanded state.
It is important to mention that you want to set the gtk.list_item.ListItem.gboolean property to FALSE when using this widget, as you want the keyboard focus to be in the treexpander, and not inside the list to make use of the keybindings.
The gtk.tree_list_model.TreeListModel must be set to not be passthrough. Then it will provide gtk.tree_list_row.TreeListRow items which can be set via gtk.tree_expander.TreeExpander.setListRow on the expander. The expander will then watch that row item automatically. gtk.tree_expander.TreeExpander.setChild sets the widget that displays the actual row contents.
gtk.tree_expander.TreeExpander can be modified with properties such as property@Gtk.TreeExpander:indent-for-icon, property@Gtk.TreeExpander:indent-for-depth, and property@Gtk.TreeExpander:hide-expander to achieve a different appearance. This can even be done to influence individual rows, for example by binding the property@Gtk.TreeExpander:hide-expander property to the item count of the model of the treelistrow, to hide the expander for rows without children, even if the row is expandable.
CSS nodes
gtk.tree_expander.TreeExpander has zero or one CSS nodes with the name "expander" that should display the expander icon. The node will be :checked when it is expanded. If the node is not expandable, an "indent" node will be displayed instead.
For every level of depth, another "indent" node is prepended.
Accessibility
Until GTK 4.10, gtk.tree_expander.TreeExpander used the gtk.types.AccessibleRole.Group role.
Since GTK 4.12, gtk.tree_expander.TreeExpander uses the gtk.types.AccessibleRole.Button role. Toggling it will change the gtk.types.AccessibleState.Expanded state.