TreeView
Object Hierarchy:
Description:
[ Version ( deprecated = true , deprecated_since = "4.10" ) ]
public class TreeView : Widget, Accessible, Buildable, ConstraintTarget, Scrollable
Warning: TreeView is deprecated since 4.10.
A widget for displaying both trees and lists
Use [class@Gtk.ListView] for lists, and [class@Gtk.ColumnView] for tabular lists
Widget that displays any object that implements the [iface@Gtk.TreeModel] interface.
Please refer to the [tree widget conceptual overview](section-tree-widget.html) for an overview of all the objects and data types related to the tree widget and how they work together.
Coordinate systems in GtkTreeView API
Several different coordinate systems are exposed in the `GtkTreeView` API. These are:
![](tree-view-coordinates.png)
- Widget coordinates: Coordinates relative to the widget (usually `widget->window`).
- Bin window coordinates: Coordinates relative to the window that GtkTreeView renders to.
- Tree coordinates: Coordinates relative to the entire scrollable area of GtkTreeView. These coordinates start at (0, 0) for row 0 of the tree.
Several functions are available for converting between the different coordinate systems. The most common translations are between widget and bin window coordinates and between bin window and tree coordinates. For the former you can use [ method@Gtk.TreeView.convert_widget_to_bin_window_coords] (and vice versa), for the latter [method@Gtk.TreeView.convert_bin_window_to_tree_coords ] (and vice versa).
`GtkTreeView` as `GtkBuildable`
The `GtkTreeView` implementation of the `GtkBuildable` interface accepts [class@Gtk.TreeViewColumn] objects as `<child>` elements and exposes the internal [class@Gtk.TreeSelection] in UI definitions.
An example of a UI definition fragment with `GtkTreeView`:
```xml <object class="GtkTreeView" id="treeview"> <property name="model">liststore1</property> <child> <object class="GtkTreeViewColumn" id="test-column"> <property name="title">Test</property> <child> <object class="GtkCellRendererText" id="test-renderer"/> <attributes> <attribute name="text">1</attribute> </attributes> </child> </object> </child> <child internal-child="selection"> <object class="GtkTreeSelection" id="selection" > <signal name="changed" handler="on_treeview_selection_changed"/> </object> </child> </object> ```
CSS nodes
``` treeview.view ├── header │ ├── button │ │ ╰── [sort-indicator] ┊ ┊ │ ╰── button │ ╰── [ sort-indicator] │ ├── [rubberband] ╰── [dndtarget] ```
`GtkTreeView` has a main CSS node with name `treeview` and style class `.view`. It has a subnode with name `header`, which is the parent for all the column header widgets' CSS nodes.
Each column header consists of a `button`, which among other content, has a child with name `sort-indicator`, which carries the `.ascending` or `.descending` style classes when the column header should show a sort indicator. The CSS is expected to provide a suitable image using the `-gtk-icon-source` property.
For rubberband selection, a subnode with name `rubberband` is used.
For the drop target location during DND, a subnode with name `dndtarget` is used.
Content:
Properties:
- public bool activate_on_single_click { get; set; }
The activate-on-single-click property specifies whether the "row-activated" signal will be emitted after a single click.
- public TreeViewGridLines enable_grid_lines { get; set; }
- public bool enable_search { get; set; }
- public bool enable_tree_lines { get; set; }
- public TreeViewColumn expander_column { get; set; }
- public bool fixed_height_mode { get; set; }
Setting the
GtkTreeView::fixed-height-mode
property to true speeds up `GtkTreeView` by assuming that all rows have the same height. - public bool headers_clickable { get; set; }
- public bool headers_visible { get; set; }
- public bool hover_expand { get; set; }
Enables or disables the hover expansion mode of
tree_view
. - public bool hover_selection { get; set; }
Enables or disables the hover selection mode of
tree_view
. - public int level_indentation { get; set; }
Extra indentation for each level.
- public TreeModel model { get; set; }
- public bool reorderable { get; set; }
- public bool rubber_banding { get; set; }
- public int search_column { get; set; }
- public bool show_expanders { get; set; }
true if the view has expanders.
- public int tooltip_column { get; set; }
Creation methods:
- public TreeView ()
Creates a new `GtkTreeView` widget.
- public TreeView.with_model (TreeModel model)
Creates a new `GtkTreeView` widget with the model initialized to
model
.
Methods:
- public int append_column (TreeViewColumn column)
Appends
column
to the list of columns. - public void collapse_all ()
Recursively collapses all visible, expanded nodes in this.
- public bool collapse_row (TreePath path)
Collapses a row (hides its child rows, if they exist).
- public void columns_autosize ()
Resizes all columns to their optimal width.
- public void convert_bin_window_to_tree_coords (int bx, int by, out int tx, out int ty)
Converts bin_window coordinates to coordinates for the tree (the full scrollable area of the tree).
- public void convert_bin_window_to_widget_coords (int bx, int by, out int wx, out int wy)
Converts bin_window coordinates to widget relative coordinates.
- public void convert_tree_to_bin_window_coords (int tx, int ty, out int bx, out int by)
Converts tree coordinates (coordinates in full scrollable area of the tree) to bin_window coordinates.
- public void convert_tree_to_widget_coords (int tx, int ty, out int wx, out int wy)
Converts tree coordinates (coordinates in full scrollable area of the tree) to widget coordinates.
- public void convert_widget_to_bin_window_coords (int wx, int wy, out int bx, out int by)
Converts widget coordinates to coordinates for the bin_window.
- public void convert_widget_to_tree_coords (int wx, int wy, out int tx, out int ty)
Converts widget coordinates to coordinates for the tree (the full scrollable area of the tree).
- public Paintable? create_row_drag_icon (TreePath path)
Creates a `cairo_surface_t` representation of the row at
path
. - public void enable_model_drag_dest (ContentFormats formats, DragAction actions)
Turns this into a drop destination for automatic DND.
- public void enable_model_drag_source (ModifierType start_button_mask, ContentFormats formats, DragAction actions)
Turns this into a drag source for automatic DND.
- public void expand_all ()
Recursively expands all nodes in the this.
- public bool expand_row (TreePath path, bool open_all)
Opens the row so its children are visible.
- public void expand_to_path (TreePath path)
Expands the row at
path
. - public bool get_activate_on_single_click ()
Gets the setting set by set_activate_on_single_click.
- public void get_background_area (TreePath? path, TreeViewColumn? column, out Rectangle rect)
Fills the bounding rectangle in bin_window coordinates for the cell at the row specified by
path
and the column specified bycolumn
. - public void get_cell_area (TreePath? path, TreeViewColumn? column, out Rectangle rect)
Fills the bounding rectangle in bin_window coordinates for the cell at the row specified by
path
and the column specified bycolumn
. - public unowned TreeViewColumn? get_column (int n)
Gets the `GtkTreeViewColumn` at the given position in the
tree_view
. - public List<unowned TreeViewColumn> get_columns ()
Returns a `GList` of all the `GtkTreeViewColumn`s currently in this.
- public void get_cursor (out TreePath? path, out unowned TreeViewColumn? focus_column)
Fills in
path
andfocus_column
with the current path and focus column. - public bool get_dest_row_at_pos (int drag_x, int drag_y, out TreePath? path, out TreeViewDropPosition pos)
Determines the destination row for a given position.
- public void get_drag_dest_row (out TreePath? path, out TreeViewDropPosition pos)
Gets information about the row that is highlighted for feedback.
- public bool get_enable_search ()
Returns whether or not the tree allows to start interactive searching by typing in text.
- public bool get_enable_tree_lines ()
Returns whether or not tree lines are drawn in this.
- public unowned TreeViewColumn? get_expander_column ()
Returns the column that is the current expander column, or null if none has been set.
- public bool get_fixed_height_mode ()
Returns whether fixed height mode is turned on for this.
- public TreeViewGridLines get_grid_lines ()
Returns which grid lines are enabled in this .
- public bool get_headers_clickable ()
Returns whether all header columns are clickable.
- public bool get_headers_visible ()
Returns true if the headers on the this are visible.
- public bool get_hover_expand ()
Returns whether hover expansion mode is turned on for this.
- public bool get_hover_selection ()
Returns whether hover selection mode is turned on for this.
- public int get_level_indentation ()
Returns the amount, in pixels, of extra indentation for child levels in this.
- public unowned TreeModel? get_model ()
Returns the model the `GtkTreeView` is based on.
- public uint get_n_columns ()
Queries the number of columns in the given this .
- public bool get_path_at_pos (int x, int y, out TreePath? path, out unowned TreeViewColumn? column, out int cell_x, out int cell_y)
Finds the path at the point (
x
,y
), relative to bin_window coordinates. - public bool get_reorderable ()
Retrieves whether the user can reorder the tree via drag-and-drop.
- public unowned TreeViewRowSeparatorFunc get_row_separator_func ()
Returns the current row separator function.
- public bool get_rubber_banding ()
Returns whether rubber banding is turned on for this.
- public int get_search_column ()
Gets the column searched on by the interactive search code.
- public unowned Editable? get_search_entry ()
Returns the `GtkEntry` which is currently in use as interactive search entry for this.
- public unowned TreeViewSearchEqualFunc get_search_equal_func ()
Returns the compare function currently in use.
- public unowned TreeSelection get_selection ()
Gets the `GtkTreeSelection` associated with this .
- public bool get_show_expanders ()
Returns whether or not expanders are drawn in this.
- public int get_tooltip_column ()
Returns the column of this’s model which is being used for displaying tooltips on this’s rows.
- public bool get_tooltip_context (int x, int y, bool keyboard_tip, out unowned TreeModel? model, out TreePath path, out TreeIter iter)
This function is supposed to be used in a query_tooltip signal handler for `GtkTreeView`.
- public bool get_visible_range (out TreePath start_path, out TreePath end_path)
Sets
start_path
andend_path
to be the first and last visible path. - public void get_visible_rect (out Rectangle visible_rect)
Fills
visible_rect
with the currently-visible region of the buffer, in tree coordinates. - public int insert_column (TreeViewColumn column, int position)
This inserts the
column
into the this atposition
. - public int insert_column_with_attributes (int position, string? title, CellRenderer cell, ...)
Creates a new `GtkTreeViewColumn` and inserts it into the this at
position
. - public int insert_column_with_data_func (int position, string title, CellRenderer cell, owned TreeCellDataFunc func)
Convenience function that inserts a new column into the `GtkTreeView` with the given cell renderer and a `GtkTreeCellDataFunc` to set cell renderer attributes (normally using data from the model).
- public bool is_blank_at_pos (int x, int y, out TreePath? path, out unowned TreeViewColumn? column, out int cell_x, out int cell_y)
Determine whether the point (
x
,y
) in this is blank, that is no cell content nor an expander arrow is drawn at the location. - public bool is_row_expanded (TreePath path)
- public bool is_rubber_banding_active ()
Returns whether a rubber banding operation is currently being done in this.
- public void map_expanded_rows (TreeViewMappingFunc func)
Calls
func
on all expanded rows. - public void move_column_after (TreeViewColumn column, TreeViewColumn? base_column)
Moves
column
to be after tobase_column
. - public int remove_column (TreeViewColumn column)
Removes
column
from this. - public void scroll_to_cell (TreePath? path, TreeViewColumn? column, bool use_align, float row_align, float col_align)
Moves the alignments of this to the position specified by
column
andpath
. - public void scroll_to_point (int tree_x, int tree_y)
Scrolls the tree view such that the top-left corner of the visible area is
tree_x
,tree_y
, wheretree_x
andtree_y
are specified in tree coordinates. - public void set_activate_on_single_click (bool single)
Cause the `GtkTreeView` row_activated signal to be emitted on a single click instead of a double click.
- public void set_column_drag_function (owned TreeViewColumnDropFunc? func)
Sets a user function for determining where a column may be dropped when dragged.
- public void set_cursor (TreePath path, TreeViewColumn? focus_column, bool start_editing)
Sets the current keyboard focus to be at
path
, and selects it. - public void set_cursor_on_cell (TreePath path, TreeViewColumn? focus_column, CellRenderer? focus_cell, bool start_editing)
Sets the current keyboard focus to be at
path
, and selects it. - public void set_drag_dest_row (TreePath? path, TreeViewDropPosition pos)
Sets the row that is highlighted for feedback.
- public void set_enable_search (bool enable_search)
If
enable_search
is set, then the user can type in text to search through the tree interactively (this is sometimes called "typeahead find"). - public void set_enable_tree_lines (bool enabled)
Sets whether to draw lines interconnecting the expanders in this.
- public void set_expander_column (TreeViewColumn? column)
Sets the column to draw the expander arrow at.
- public void set_fixed_height_mode (bool enable)
Enables or disables the fixed height mode of this .
- public void set_grid_lines (TreeViewGridLines grid_lines)
Sets which grid lines to draw in this.
- public void set_headers_clickable (bool setting)
Allow the column title buttons to be clicked.
- public void set_headers_visible (bool headers_visible)
Sets the visibility state of the headers.
- public void set_hover_expand (bool expand)
Enables or disables the hover expansion mode of this.
- public void set_hover_selection (bool hover)
Enables or disables the hover selection mode of this.
- public void set_level_indentation (int indentation)
Sets the amount of extra indentation for child levels to use in this in addition to the default indentation.
- public void set_model (TreeModel? model)
Sets the model for a `GtkTreeView`.
- public void set_reorderable (bool reorderable)
This function is a convenience function to allow you to reorder models that support the `GtkTreeDragSourceIface` and the `GtkTreeDragDestIface`.
- public void set_row_separator_func (owned TreeViewRowSeparatorFunc? func)
Sets the row separator function, which is used to determine whether a row should be drawn as a separator.
- public void set_rubber_banding (bool enable)
Enables or disables rubber banding in this .
- public void set_search_column (int column)
Sets
column
as the column where the interactive search code should search in for the current model. - public void set_search_entry (Editable? entry)
Sets the entry which the interactive search code will use for this this.
- public void set_search_equal_func (owned TreeViewSearchEqualFunc search_equal_func)
Sets the compare function for the interactive search capabilities; note that somewhat like
strcmp
returning 0 for equality `GtkTreeView`SearchEqualFunc returns false on matches. - public void set_show_expanders (bool enabled)
Sets whether to draw and enable expanders and indent child rows in this.
- public void set_tooltip_cell (Tooltip tooltip, TreePath? path, TreeViewColumn? column, CellRenderer? cell)
Sets the tip area of
tooltip
to the areapath
,column
andcell
have in common. - public void set_tooltip_column (int column)
If you only plan to have simple (text-only) tooltips on full rows, you can use this function to have `GtkTreeView` handle these automatically for you.
- public void set_tooltip_row (Tooltip tooltip, TreePath path)
Sets the tip area of
tooltip
to be the area covered by the row atpath
. - public void unset_rows_drag_dest ()
Undoes the effect of enable_model_drag_dest.
- public void unset_rows_drag_source ()
Undoes the effect of enable_model_drag_source.
Signals:
- public virtual signal void columns_changed ()
The number of columns of the treeview has changed.
- public virtual signal void cursor_changed ()
The position of the cursor (focused cell) has changed.
- public virtual signal bool expand_collapse_cursor_row (bool logical, bool expand, bool open_all)
- public virtual signal bool move_cursor (MovementStep step, int count, bool extend, bool modify)
The `GtkTreeView`move_cursor signal is a [keybinding signal][class@Gtk.
- public virtual signal void row_activated (TreePath path, TreeViewColumn? column)
The "row-activated" signal is emitted when the method [method@Gtk.
- public virtual signal void row_collapsed (TreeIter iter, TreePath path)
The given row has been collapsed (child nodes are hidden).
- public virtual signal void row_expanded (TreeIter iter, TreePath path)
The given row has been expanded (child nodes are shown).
- public virtual signal bool select_all ()
- public virtual signal bool select_cursor_parent ()
- public virtual signal bool select_cursor_row (bool start_editing)
- public virtual signal bool start_interactive_search ()
- public virtual signal bool test_collapse_row (TreeIter iter, TreePath path)
The given row is about to be collapsed (hide its children nodes).
- public virtual signal bool test_expand_row (TreeIter iter, TreePath path)
The given row is about to be expanded (show its children nodes).
- public virtual signal bool toggle_cursor_row ()
- public virtual signal bool unselect_all ()
Inherited Members:
- action_set_enabled
- activate
- activate_action
- activate_action_variant
- activate_default
- add_binding
- add_binding_action
- add_binding_signal
- add_controller
- add_css_class
- add_mnemonic_label
- add_shortcut
- add_tick_callback
- allocate
- allocate_size
- bind_template_callback_full
- bind_template_child_full
- can_focus
- can_target
- child_focus
- compute_bounds
- compute_expand
- compute_expand_internal
- compute_point
- compute_transform
- contains
- create_pango_context
- create_pango_layout
- css_changed
- css_classes
- css_name
- cursor
- destroy
- direction_changed
- dispose_template
- error_bell
- focus
- focus_on_click
- focusable
- get_accessible_role
- get_activate_signal
- get_allocated_baseline
- get_allocated_height
- get_allocated_width
- get_allocation
- get_ancestor
- get_baseline
- get_can_focus
- get_can_target
- get_child_visible
- get_clipboard
- get_color
- get_css_classes
- get_css_name
- get_cursor
- get_default_direction
- get_direction
- get_display
- get_first_child
- get_focus_child
- get_focus_on_click
- get_focusable
- get_font_map
- get_font_options
- get_frame_clock
- get_halign
- get_has_tooltip
- get_height
- get_hexpand
- get_hexpand_set
- get_last_child
- get_layout_manager
- get_layout_manager_type
- get_mapped
- get_margin_bottom
- get_margin_end
- get_margin_start
- get_margin_top
- get_name
- get_native
- get_next_sibling
- get_opacity
- get_overflow
- get_pango_context
- get_parent
- get_preferred_size
- get_prev_sibling
- get_primary_clipboard
- get_realized
- get_receives_default
- get_request_mode
- get_root
- get_scale_factor
- get_sensitive
- get_settings
- get_size
- get_size_request
- get_state_flags
- get_style_context
- get_template_child
- get_tooltip_markup
- get_tooltip_text
- get_valign
- get_vexpand
- get_vexpand_set
- get_visible
- get_width
- grab_focus
- halign
- has_css_class
- has_default
- has_focus
- has_tooltip
- has_visible_focus
- height_request
- hexpand
- hexpand_set
- hide
- in_destruction
- init_template
- insert_action_group
- insert_after
- insert_before
- install_action
- install_property_action
- is_ancestor
- is_drawable
- is_focus
- is_sensitive
- is_visible
- keynav_failed
- layout_manager
- list_mnemonic_labels
- map
- margin_bottom
- margin_end
- margin_start
- margin_top
- measure
- mnemonic_activate
- move_focus
- name
- observe_children
- observe_controllers
- opacity
- overflow
- parent
- pick
- query_action
- query_tooltip
- queue_allocate
- queue_draw
- queue_resize
- realize
- receives_default
- remove_controller
- remove_css_class
- remove_mnemonic_label
- remove_tick_callback
- root
- scale_factor
- sensitive
- set_accessible_role
- set_activate_signal
- set_activate_signal_from_name
- set_can_focus
- set_can_target
- set_child_visible
- set_css_classes
- set_css_name
- set_cursor
- set_cursor_from_name
- set_default_direction
- set_direction
- set_focus_child
- set_focus_on_click
- set_focusable
- set_font_map
- set_font_options
- set_halign
- set_has_tooltip
- set_hexpand
- set_hexpand_set
- set_layout_manager
- set_layout_manager_type
- set_margin_bottom
- set_margin_end
- set_margin_start
- set_margin_top
- set_name
- set_opacity
- set_overflow
- set_parent
- set_receives_default
- set_sensitive
- set_size_request
- set_state_flags
- set_template
- set_template_from_resource
- set_template_scope
- set_tooltip_markup
- set_tooltip_text
- set_valign
- set_vexpand
- set_vexpand_set
- set_visible
- should_layout
- show
- size_allocate
- snapshot
- snapshot_child
- state_flags_changed
- system_setting_changed
- tooltip_markup
- tooltip_text
- translate_coordinates
- trigger_tooltip_query
- unmap
- unparent
- unrealize
- unroot
- unset_state_flags
- valign
- vexpand
- vexpand_set
- visible
- width_request