GTK+ 2.0 Tree View Tutorial using Ocaml

Tim-Philipp Muller

Ocaml adaptation: SooHyoung Oh

This is a tutorial on how to use GTK+ 2.0 GtkTreeView widget in Ocaml language. Ocaml has a very nice Gtk+ interface called LablGtk in which GtkTreeView widget is implemented as GTree module.

The LablGtk version used here is LablGTK 2.4.0.

This tutorial is adapted from the original C language version written by Tim-Philipp Muller.

Please mail all comments and suggestions about Ocaml adaptation to

There is also a version in PDF format (for easier printing) and the raw docbook XML source document.

Some examples can be found in treeview_tutorial_examples.tar.gz tarball.

This tutorial is work-in-progress. The latest version can be found at http://compiler.kaist.ac.kr/~shoh/ocaml/lablgtk2/treeview-tutorial/index.html.

"Gtk+ 2.0 Tutorial using Ocaml" can be found at http://compiler.kaist.ac.kr/~shoh/ocaml/lablgtk2/lablgtk2-tutorial/index.html.

Last updated: 2004-09-18


Table of Contents
1. Lists and Trees: the GTree Module
1.1. Hello World
2. Components: Model, Renderer, Column, View
3. GTree.models for Data Storage: GTree.list_store and GTree.tree_store
3.1. How Data is Organised in a Store
3.2. Refering to Rows: Gtk.tree_iter, Gtk.tree_path, Gtk.row_reference, GTree.row_reference
3.2.1. Gtk.tree_path
3.2.2. Gtk.tree_iter
3.2.3. Gtk.row_reference, GTree.row_reference
3.2.4. Usage
3.3. Adding Rows to a Store
3.3.1. Adding Rows to a List Store
3.3.2. Adding Rows to a Tree Store
3.3.3. Speed Issues when Adding a Lot of Rows
3.4. Manipulating Row Data
3.5. Retrieving Row Data
3.6. Removing Rows
3.7. Removing Multiple Rows
4. Creating a Tree View
4.1. Connecting Tree View and Model
4.2. Tree View Look and Feel
5. Mapping Data to the Screen: GTree.view_column and GTree.cell_renderer_*
5.1. Cell Renderers
5.2. Attributes
5.3. Cell Data Functions
5.4. GTree.cell_renderer_text and Integer, Boolean and Float Types
5.5. GTree.cell_renderer_text, UTF8, and pango markup
5.6. A Working Example
5.7. How to Make a Whole Row Bold or Coloured
5.8. How to Pack Icons into the Tree View
6. Selections, Double-Clicks and Context Menus
6.1. Handling Selections
6.1.1. Selection Modes
6.1.2. Getting the Currently Selected Rows
6.1.3. Using Selection Functions
6.1.4. Checking Whether a Row is Selected
6.1.5. Selecting and Unselecting Rows
6.2. Double-Clicks on a Row
6.3. Context Menus on Right Click
7. Sorting
7.1. GTree.tree_sortable
7.2. Sorting and Tree View Column Headers
8. Editable Cells
8.1. Editable Text Cells
8.1.1. Setting the cursor to a specific cell
8.2. Editable Toggle and Radio Button Cells
9. Other Resources
10. Copyright, License, Credits, and Revision History
10.1. Copyright and License
10.1.1. Ocaml Adaptation
10.1.2. Original Document
10.2. Credits
10.2.1. Ocaml Adaptation
10.2.2. Original Document
10.3. Revision History
10.3.1. Ocaml Adaptation
10.3.2. Original Document
List of Figures
3-1. Tree Paths
5-1. Cell Renderer Properties
5-2. GtkTreeViewColumns and GtkCellRenderers
5-3. Persistent Cell Renderer Properties