1.206 <GtkTreeExpander>

Class: <GtkTreeExpander>

It derives from <GtkWidget>.

Provides an expander for a tree-like list.

It is typically placed as a bottommost child into a <GtkListView> to allow users to expand and collapse children in a list with a <GtkTreeListModel>. <GtkTreeExpander> 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 list-item:focusable 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 <GtkTreeListModel> must be set to not be passthrough. Then it will provide <GtkTreeListRow> items which can be set via tree-expander:set-list-row on the expander. The expander will then watch that row item automatically. tree-expander:set-child sets the widget that displays the actual row contents.

<GtkTreeExpander> can be modified with properties such as tree-expander:indent-for-icon, tree-expander:indent-for-depth, and tree-expander:hide-expander to achieve a different appearance. This can even be done to influence individual rows, for example by binding the tree-expander: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.

Shortcuts and Gestures

<GtkTreeExpander> supports the following keyboard shortcuts:

  • + or * expands the expander.
  • - or / collapses the expander.
  • Left and right arrow keys, when combined with Shift or Ctrl+Shift, will expand or collapse, depending on the locale’s text direction.
  • Ctrl+␣ toggles the expander state.

The row can also expand on drag gestures.

Actions

<GtkTreeExpander> defines a set of built-in actions:

  • listitem.expand expands the expander if it can be expanded.
  • listitem.collapse collapses the expander.
  • listitem.toggle-expand tries to expand the expander if it was collapsed or collapses it if it was expanded.

CSS nodes

treeexpander
├── [indent]*
├── [expander]
╰── <child>

<GtkTreeExpander> 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, <GtkTreeExpander> used the Gtk.AccessibleRole.group role.

Since GTK 4.12, <GtkTreeExpander> uses the Gtk.AccessibleRole.button role. Toggling it will change the expanded state.

Properties

Property: tree-expander:child self

The child widget with the actual contents.

Its value is a <GtkWidget>, or #f.

Set it with (set! (tree-expander:child self) value).

Property: tree-expander:hide-expander self

Whether the expander icon should be hidden in a GtkTreeListRow. Note that this property simply hides the icon. The actions and keybinding (i.e. collapse and expand) are not affected by this property.

A common use for this property would be to bind to the number of children in a GtkTreeListRow’s model in order to hide the expander when a row has no children.

Its value is a boolean.

Set it with (set! (tree-expander:hide-expander self) value).

Property: tree-expander:indent-for-depth self

TreeExpander indents the child according to its depth.

Its value is a boolean.

Set it with (set! (tree-expander:indent-for-depth self) value).

Property: tree-expander:indent-for-icon self

TreeExpander indents the child by the width of an expander-icon if it is not expandable.

Its value is a boolean.

Set it with (set! (tree-expander:indent-for-icon self) value).

Property: tree-expander:item self

The item held by this expander’s row.

Its value is a <GObject>, or #f.

It is read only.

Property: tree-expander:list-row self

The list row to track for expander state.

Its value is a <GtkTreeListRow>, or #f.

Set it with (set! (tree-expander:list-row self) value).

Procedures

Method: tree-expander:get-child self ⇒ %return
Method: get-child self ⇒ %return

Gets the child widget displayed by self.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander>

%return

Returned: a <GtkWidget>, or #f.

The child displayed by self

Method: tree-expander:get-hide-expander? self ⇒ %return
Method: get-hide-expander? self ⇒ %return

Gets whether the TreeExpander should be hidden in a GtkTreeListRow.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander>

%return

Returned: a boolean.

TRUE if the expander icon should be hidden. Otherwise FALSE.

Method: tree-expander:get-indent-for-depth? self ⇒ %return
Method: get-indent-for-depth? self ⇒ %return

TreeExpander indents each level of depth with an additional indent.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander>

%return

Returned: a boolean.

TRUE if the child should be indented . Otherwise FALSE.

Method: tree-expander:get-indent-for-icon? self ⇒ %return
Method: get-indent-for-icon? self ⇒ %return

TreeExpander indents the child by the width of an expander-icon if it is not expandable.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander>

%return

Returned: a boolean.

TRUE if the child should be indented when not expandable. Otherwise FALSE.

Method: tree-expander:get-item self ⇒ %return
Method: get-item self ⇒ %return

Forwards the item set on the <GtkTreeListRow> that self is managing.

This call is essentially equivalent to calling:

gtk_tree_list_row_get_item (gtk_tree_expander_get_list_row (@self));
self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander>

%return

Returned: a <GObject>, or #f.

The item of the row

Method: tree-expander:get-list-row self ⇒ %return
Method: get-list-row self ⇒ %return

Gets the list row managed by self.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander>

%return

Returned: a <GtkTreeListRow>, or #f.

The list row displayed by self

Procedure: tree-expander:new ⇒ %return

Creates a new <GtkTreeExpander>

%return

Returned: a <GtkWidget>.

a new <GtkTreeExpander>

Method: tree-expander:set-child self [child]
Method: set-child self [child]

Sets the content widget to display.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander>

child

Passed, or left out: a <GtkWidget>, or #f.

a <GtkWidget>

Method: tree-expander:set-hide-expander self hide-expander
Method: set-hide-expander self hide-expander

Sets whether the expander icon should be visible in a GtkTreeListRow.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander> widget

hide-expander

Passed: a boolean.

TRUE if the expander should be hidden. Otherwise FALSE.

Method: tree-expander:set-indent-for-depth self indent-for-depth
Method: set-indent-for-depth self indent-for-depth

Sets if the TreeExpander should indent the child according to its depth.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander> widget

indent-for-depth

Passed: a boolean.

TRUE if the child should be indented. Otherwise FALSE.

Method: tree-expander:set-indent-for-icon self indent-for-icon
Method: set-indent-for-icon self indent-for-icon

Sets if the TreeExpander should indent the child by the width of an expander-icon when it is not expandable.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander> widget

indent-for-icon

Passed: a boolean.

TRUE if the child should be indented without expander. Otherwise FALSE.

Method: tree-expander:set-list-row self [list-row]
Method: set-list-row self [list-row]

Sets the tree list row that this expander should manage.

self

Passed: a <GtkTreeExpander>.

a <GtkTreeExpander> widget

list-row

Passed, or left out: a <GtkTreeListRow>, or #f.

a <GtkTreeListRow>