TreeView


Object Hierarchy:

Gtk.TreeView Gtk.TreeView Gtk.TreeView Gtk.Container Gtk.Container Gtk.Container->Gtk.TreeView Gtk.Widget Gtk.Widget Gtk.Widget->Gtk.Container GLib.InitiallyUnowned GLib.InitiallyUnowned GLib.InitiallyUnowned->Gtk.Widget GLib.Object GLib.Object GLib.Object->GLib.InitiallyUnowned Atk.Implementor Atk.Implementor Atk.Implementor->Gtk.TreeView Atk.Implementor->Gtk.Container Atk.Implementor->Gtk.Widget Gtk.Buildable Gtk.Buildable Gtk.Buildable->Gtk.TreeView Gtk.Buildable->Gtk.Container Gtk.Buildable->Gtk.Widget Gtk.Scrollable Gtk.Scrollable Gtk.Scrollable->Gtk.TreeView

Description:

[ CCode ( type_id = "gtk_tree_view_get_type ()" ) ]
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


Namespace: Gtk
Package: gtk+-3.0

Content:

Properties:

Creation methods:

Methods:

Signals:

Inherited Members:

All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor