TreeView
Object Hierarchy:
Description:
public class TreeView : Container, Implementor, Buildable, Scrollable
Widget that displays any object that implements the TreeModel interface.
Please refer to the [tree widget conceptual overview](TreeWidget.html) for an overview of all the objects and data types related to the tree widget and how they work together.
Several different coordinate systems are exposed in the GtkTreeView API. These are:
![](tree-view-coordinates.png)
Coordinate systems in GtkTreeView API:
- 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 convert_widget_to_bin_window_coords (and vice versa ), for the latter convert_bin_window_to_tree_coords ( and vice versa).
GtkTreeView as GtkBuildable
The GtkTreeView implementation of the GtkBuildable interface accepts TreeViewColumn objects as `<child>` elements and exposes the internal TreeSelection in UI definitions.
An example of a UI definition fragment with GtkTreeView:
<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
│ ├── <column header>
┊ ┊
│ ╰── <column header>
│
╰── [rubberband]
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.
For rubberband selection, a subnode with name rubberband is used.
Example: TreeView:
public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.TreeView";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (350, 70);
// The Model:
Gtk.ListStore list_store = new Gtk.ListStore (2, typeof (string), typeof (int));
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter, 0, "Burgenland", 1, 13);
list_store.append (out iter);
list_store.set (iter, 0, "Carinthia", 1, 17);
list_store.append (out iter);
list_store.set (iter, 0, "Lower Austria", 1, 75);
list_store.append (out iter);
list_store.set (iter, 0, "Upper Austria", 1, 32);
list_store.append (out iter);
list_store.set (iter, 0, "Salzburg", 1, 10);
list_store.append (out iter);
list_store.set (iter, 0, "Styria", 1, 34);
list_store.append (out iter);
list_store.set (iter, 0, "Tyrol", 1, 11);
list_store.append (out iter);
list_store.set (iter, 0, "Vorarlberg", 1, 5);
list_store.append (out iter);
list_store.set (iter, 0, "Vienna", 1, 1);
// The View:
Gtk.TreeView view = new Gtk.TreeView.with_model (list_store);
this.add (view);
Gtk.CellRendererText cell = new Gtk.CellRendererText ();
view.insert_column_with_attributes (-1, "State", cell, "text", 0);
view.insert_column_with_attributes (-1, "Cities", cell, "text", 1);
}
public static int main (string[] args) {
Gtk.init (ref args);
Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}
valac --pkg gtk+-3.0 Gtk.TreeView.vala
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 TreeView 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 bool rules_hint { get; set; }
Sets a hint to the theme to draw rows in alternating colors.
- 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 TreeView widget.
- public TreeView.with_model (TreeModel model)
Creates a new TreeView 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 (see get_bin_window) 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 (see get_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 Surface create_row_drag_icon (TreePath path)
Creates a XlibSurface representation of the row at
path
. - public void enable_model_drag_dest (TargetEntry[] targets, DragAction actions)
Turns this into a drop destination for automatic DND.
- public void enable_model_drag_source (ModifierType start_button_mask, TargetEntry[] targets, 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 unowned Window? get_bin_window ()
Returns the window that this renders to.
- 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 TreeViewColumn at the given position in the
tree_view
. - public List<unowned TreeViewColumn> get_columns ()
Returns a List of all the TreeViewColumn 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.
- 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 unowned Adjustment get_hadjustment ()
Gets the Adjustment currently being used for the horizontal aspect.
- 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 TreeView 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 (please see get_bin_window). - 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 bool get_rules_hint ()
Gets the setting set by set_rules_hint.
- public int get_search_column ()
Gets the column searched on by the interactive search code.
- public unowned Entry get_search_entry ()
Returns the Entry 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 TreeViewSearchPositionFunc get_search_position_func ()
Returns the positioning function currently in use.
- public unowned TreeSelection get_selection ()
Gets the TreeSelection 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 (ref int x, ref 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 TreeView.
- public unowned Adjustment get_vadjustment ()
Gets the Adjustment currently being used for the vertical aspect.
- 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 TreeViewColumn 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 TreeView with the given cell renderer and a TreeCellDataFunc 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 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_destroy_count_func (owned TreeDestroyCountFunc? func)
This function should almost never be used.
- 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_hadjustment (Adjustment? adjustment)
Sets the Adjustment for the current horizontal aspect.
- 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 TreeView.
- public void set_reorderable (bool reorderable)
This function is a convenience function to allow you to reorder models that support the TreeDragSource and the TreeDragDest.
- 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_rules_hint (bool setting)
Sets a hint for the theme to draw even/odd rows in the this with different colors, also known as "zebra striping".
- 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 (Entry? 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 TreeViewSearchEqualFunc returns false on matches. - public void set_search_position_func (owned TreeViewSearchPositionFunc? func)
Sets the function to use when positioning the search dialog.
- 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 TreeView 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 set_vadjustment (Adjustment? adjustment)
Sets the Adjustment for the current vertical aspect.
- 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)
The move_cursor signal is a [keybinding signal][ GtkBindingSignal] which gets emitted when the user presses one of the cursor keys.
- public virtual signal void row_activated (TreePath path, TreeViewColumn column)
The "row-activated" signal is emitted when the method row_activated is called, when the user double clicks a treeview row with the "activate-on-single-click" property set to false, or when the user single clicks a row when the "activate-on-single-click" property set to true.
- 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:
- accel_closures_changed
- activate
- add_accelerator
- add_device_events
- add_events
- add_mnemonic_label
- add_tick_callback
- adjust_baseline_allocation
- adjust_baseline_request
- adjust_size_allocation
- adjust_size_request
- app_paintable
- bind_template_callback_full
- bind_template_child_full
- button_press_event
- button_release_event
- can_activate_accel
- can_default
- can_focus
- child_focus
- child_notify
- class_path
- composite_child
- composited_changed
- compute_expand
- compute_expand_internal
- configure_event
- create_pango_context
- create_pango_layout
- damage_event
- delete_event
- destroy
- destroy_event
- destroyed
- device_is_shadowed
- direction_changed
- dispatch_child_properties_changed
- double_buffered
- drag_begin
- drag_data_delete
- drag_data_get
- drag_data_received
- drag_drop
- drag_end
- drag_failed
- drag_leave
- drag_motion
- draw
- draw_to_cairo_context
- ensure_style
- enter_notify_event
- error_bell
- event
- event_after
- events
- expand
- find_style_property
- focus
- focus_in_event
- focus_on_click
- focus_out_event
- freeze_child_notify
- get_accessible
- get_action_group
- get_allocated_baseline
- get_allocated_height
- get_allocated_size
- get_allocated_width
- get_allocation
- get_ancestor
- get_app_paintable
- get_can_default
- get_can_focus
- get_child_requisition
- get_child_visible
- get_clip
- get_clipboard
- get_composite_name
- get_css_name
- get_default_direction
- get_default_style
- get_device_enabled
- get_device_events
- get_direction
- get_display
- get_double_buffered
- get_events
- get_focus_on_click
- get_font_map
- get_font_options
- get_frame_clock
- get_halign
- get_has_tooltip
- get_has_window
- get_hexpand
- get_hexpand_set
- get_mapped
- get_margin_bottom
- get_margin_end
- get_margin_left
- get_margin_right
- get_margin_start
- get_margin_top
- get_modifier_mask
- get_modifier_style
- get_no_show_all
- get_opacity
- get_pango_context
- get_parent
- get_parent_window
- get_path
- get_pointer
- get_preferred_height
- get_preferred_height_and_baseline_for_width
- get_preferred_height_for_width
- get_preferred_height_for_width_internal
- get_preferred_height_internal
- get_preferred_size
- get_preferred_width
- get_preferred_width_for_height
- get_preferred_width_for_height_internal
- get_preferred_width_internal
- get_realized
- get_receives_default
- get_request_mode
- get_requisition
- get_root_window
- get_scale_factor
- get_screen
- get_sensitive
- get_settings
- get_size_request
- get_state
- get_state_flags
- get_style
- get_style_context
- get_support_multidevice
- get_template_child
- get_tooltip_markup
- get_tooltip_text
- get_tooltip_window
- get_toplevel
- get_valign
- get_valign_with_baseline
- get_vexpand
- get_vexpand_set
- get_visible
- get_visual
- get_window
- grab_broken_event
- grab_default
- grab_focus
- grab_notify
- halign
- has_default
- has_focus
- has_grab
- has_rc_style
- has_screen
- has_tooltip
- has_visible_focus
- height_request
- hexpand
- hexpand_set
- hide
- hide_on_delete
- hierarchy_changed
- in_destruction
- init_template
- input_shape_combine_region
- insert_action_group
- install_style_property
- install_style_property_parser
- intersect
- is_ancestor
- is_composited
- is_drawable
- is_focus
- is_sensitive
- is_toplevel
- is_visible
- key_press_event
- key_release_event
- keynav_failed
- leave_notify_event
- list_accel_closures
- list_action_prefixes
- list_mnemonic_labels
- list_style_properties
- map
- map_event
- margin
- margin_bottom
- margin_end
- margin_left
- margin_right
- margin_start
- margin_top
- mnemonic_activate
- modify_base
- modify_bg
- modify_cursor
- modify_fg
- modify_font
- modify_style
- modify_text
- motion_notify_event
- move_focus
- name
- no_show_all
- opacity
- override_background_color
- override_color
- override_cursor
- override_font
- override_symbolic_color
- parent
- parent_set
- path
- pop_composite_child
- popup_menu
- property_notify_event
- proximity_in_event
- proximity_out_event
- push_composite_child
- query_tooltip
- queue_allocate
- queue_compute_expand
- queue_draw
- queue_draw_area
- queue_draw_region
- queue_resize
- queue_resize_no_redraw
- realize
- receives_default
- region_intersect
- register_window
- remove_accelerator
- remove_mnemonic_label
- remove_tick_callback
- render_icon
- render_icon_pixbuf
- reparent
- reset_rc_styles
- reset_style
- scale_factor
- screen_changed
- scroll_event
- selection_clear_event
- selection_get
- selection_notify_event
- selection_received
- selection_request_event
- send_expose
- send_focus_change
- sensitive
- set_accel_path
- set_accessible_role
- set_accessible_type
- set_allocation
- set_app_paintable
- set_can_default
- set_can_focus
- set_child_visible
- set_clip
- set_composite_name
- set_connect_func
- set_css_name
- set_default_direction
- set_device_enabled
- set_device_events
- set_direction
- set_double_buffered
- set_events
- set_focus_on_click
- set_font_map
- set_font_options
- set_halign
- set_has_tooltip
- set_has_window
- set_hexpand
- set_hexpand_set
- set_mapped
- set_margin_bottom
- set_margin_end
- set_margin_left
- set_margin_right
- set_margin_start
- set_margin_top
- set_no_show_all
- set_opacity
- set_parent
- set_parent_window
- set_realized
- set_receives_default
- set_redraw_on_allocate
- set_sensitive
- set_size_request
- set_state
- set_state_flags
- set_style
- set_support_multidevice
- set_template
- set_template_from_resource
- set_tooltip_markup
- set_tooltip_text
- set_tooltip_window
- set_valign
- set_vexpand
- set_vexpand_set
- set_visible
- set_visual
- set_window
- shape_combine_region
- show
- show_all
- show_help
- show_now
- size_allocate
- size_allocate_with_baseline
- size_request
- state_changed
- state_flags_changed
- style
- style_attach
- style_get
- style_get_property
- style_get_valist
- style_set
- style_updated
- thaw_child_notify
- tooltip_markup
- tooltip_text
- touch_event
- translate_coordinates
- trigger_tooltip_query
- unmap
- unmap_event
- unparent
- unrealize
- unregister_window
- unset_state_flags
- valign
- vexpand
- vexpand_set
- visibility_notify_event
- visible
- width_request
- window_state_event