Gtk.TreeExpander

g GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.TreeExpander Gtk.TreeExpander Gtk.Widget->Gtk.TreeExpander

Subclasses:

None

Methods

Inherited:

Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new ()

get_child ()

get_hide_expander ()

get_indent_for_depth ()

get_indent_for_icon ()

get_item ()

get_list_row ()

set_child (child)

set_hide_expander (hide_expander)

set_indent_for_depth (indent_for_depth)

set_indent_for_icon (indent_for_icon)

set_list_row (list_row)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)

Properties

Inherited:

Gtk.Widget (34), Gtk.Accessible (1)

Name

Type

Flags

Short Description

child

Gtk.Widget

r/w/en

hide-expander

bool

r/w/en

indent-for-depth

bool

r/w/en

indent-for-icon

bool

r/w/en

item

GObject.Object

r/en

list-row

Gtk.TreeListRow

r/w/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Gtk.TreeExpander(**kwargs)
Bases:

Gtk.Widget

Abstract:

No

Structure:

Gtk.TreeExpanderClass

GtkTreeExpander is a widget that provides an expander for a 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 [class`Gtk`.TreeListModel]. 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 [property`Gtk`.ListItem: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 [class`Gtk`.TreeListRow] items which can be set via [method`Gtk`.TreeExpander.set_list_row] on the expander. The expander will then watch that row item automatically. [method`Gtk`.TreeExpander.set_child] sets the widget that displays the actual row contents.

GtkTreeExpander 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

`` 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_ACCESSIBLE_ROLE_GROUP role.

Since GTK 4.12, GtkTreeExpander uses the GTK_ACCESSIBLE_ROLE_BUTTON role. Toggling it will change the GTK_ACCESSIBLE_STATE_EXPANDED state.

classmethod new()[source]
Returns:

a new GtkTreeExpander

Return type:

Gtk.Widget

Creates a new GtkTreeExpander

get_child()[source]
Returns:

The child displayed by self

Return type:

Gtk.Widget or None

Gets the child widget displayed by self.

get_hide_expander()[source]
Returns:

True if the expander icon should be hidden. Otherwise False.

Return type:

bool

Gets whether the TreeExpander should be hidden in a Gtk.TreeListRow.

New in version 4.10.

get_indent_for_depth()[source]
Returns:

True if the child should be indented . Otherwise False.

Return type:

bool

TreeExpander indents each level of depth with an additional indent.

New in version 4.10.

get_indent_for_icon()[source]
Returns:

True if the child should be indented when not expandable. Otherwise False.

Return type:

bool

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

New in version 4.6.

get_item()[source]
Returns:

The item of the row

Return type:

GObject.Object or None

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

This call is essentially equivalent to calling:

``c gtk_tree_list_row_get_item (gtk_tree_expander_get_list_row (@self)); ``

get_list_row()[source]
Returns:

The list row displayed by self

Return type:

Gtk.TreeListRow or None

Gets the list row managed by self.

set_child(child)[source]
Parameters:

child (Gtk.Widget or None) – a GtkWidget

Sets the content widget to display.

set_hide_expander(hide_expander)[source]
Parameters:

hide_expander (bool) – True if the expander should be hidden. Otherwise False.

Sets whether the expander icon should be visible in a Gtk.TreeListRow.

New in version 4.10.

set_indent_for_depth(indent_for_depth)[source]
Parameters:

indent_for_depth (bool) – True if the child should be indented. Otherwise False.

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

New in version 4.10.

set_indent_for_icon(indent_for_icon)[source]
Parameters:

indent_for_icon (bool) – True if the child should be indented without expander. Otherwise False.

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

New in version 4.6.

set_list_row(list_row)[source]
Parameters:

list_row (Gtk.TreeListRow or None) – a GtkTreeListRow

Sets the tree list row that this expander should manage.

Property Details

Gtk.TreeExpander.props.child
Name:

child

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The child widget with the actual contents.

Gtk.TreeExpander.props.hide_expander
Name:

hide-expander

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the expander icon should be hidden in a Gtk.TreeListRow. 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 Gtk.TreeListRow's model in order to hide the expander when a row has no children.

New in version 4.10.

Gtk.TreeExpander.props.indent_for_depth
Name:

indent-for-depth

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

TreeExpander indents the child according to its depth.

New in version 4.10.

Gtk.TreeExpander.props.indent_for_icon
Name:

indent-for-icon

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

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

New in version 4.6.

Gtk.TreeExpander.props.item
Name:

item

Type:

GObject.Object

Default Value:

None

Flags:

READABLE, EXPLICIT_NOTIFY

The item held by this expander’s row.

Gtk.TreeExpander.props.list_row
Name:

list-row

Type:

Gtk.TreeListRow

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The list row to track for expander state.