GTK+ By Example/Tree View
This chapter has been based on this work [1]
Chapter Sections
[edit | edit source]- Lists and Trees: the GtkTreeView Widget
- Components: Model, Renderer, Column, View
- GtkTreeModels for Data Storage: GtkListStore and GtkTreeStore
- Creating a Tree View
- Mapping Data to the Screen: GtkTreeViewColumn and GtkCellRenderer
- Selections, Double-Clicks and Context Menus
- Sorting
- Editable Cells
- Miscellaneous
- Drag'n'Drop (DnD) **** needs revision ***
- Writing Custom Models
- Writing Custom Cell Renderers
- Other Resources
Original License (Tree View)
[edit | edit source]Copyright (c) 2003-2004 Tim-Philipp Müller <tim at centricular dot net>
This tutorial may be redistributed and modified freely in any form, as long as all authors are given due credit for their work and all non-trivial changes by third parties are clearly marked as such either within the document (e.g. in a revision history), or at an external and publicly accessible place that is referred to in the document (such as a CVS/SVN/git repository).
Original Version Credits
[edit | edit source]Thanks to Axel C. for proof-reading the first drafts, for many suggestions, and for introducing me to the tree view widget in the first place (back then when I was still convinced that porting to Gtk+-2.x was unnecessary, Gtk+-1.2 applications looked nice, and Aristotle had already said everything about politics that needs to be said).
- Harring Figueiredo shed some light on how GtkListStore and GtkTreeStore deal with pixbufs.
- Ken Rastatter suggested some additional topics (with complete references even).
- Both Andrej Prsa and Alan B. Canon sent me a couple of suggestions, and 'taf2', Massimo Mangoni and others spotted some typos.
- Many thanks to all of them, and of course also to kris and everyone else in #gtk+.
Original Revision History
[edit | edit source]14.3. Revision History
5th January 2008
- Update some broken links; remove references to external cell renderers that have been obsoleted by Gtk adding such renderers.
5th June 2005
- Remove unnecessary col = gtk_tree_view_column_new() im hello world code (leftover from migration to convenience functions).
3rd February 2005
- Point out that GObjects such as GdkPixbufs retrieved with gtk_tree_model_get() need to be g_object_unref()'ed after use, as gtk_tree_model_get() adds a reference.
- Added explicit (gint) event->x double to int conversion to code snippet using gtk_tree_view_get_path_at_pos() to avoid compiler warnings.
9th September 2004
- Fixed another mistake in tree path explanation: text did not correspond picture (s/movie clips/movie trailers/); (thanks to Benjamin Brandt for spotting it).
6th August 2004
- Fixed mistake in tree path explanation (s/4th/5th/) (thanks to both Andrew Kirillov and Benjamin Brandt for spotting it).
30th April 2004
- Added Hello World
31st March 2004
- Fixed fatal typo in custom list code: g_assert() in custom_list_init() should be ==, not != (spotted by mmc).
- Added link to Owen Taylor's mail on the GtkTreeView Drag'n'Drop API.
24th January 2004
- Fixed typo in code example (remove n-th row example) (Thanks to roel for spotting it).
- Changed 'Context menus' section title
19th January 2004
- Expanded section on GtkTreeRowReferences, and on removing multiple rows.
8th January 2004
- Added tiny section on Glade and treeviews
- Added more detail to the section describing GtkTreePath, GtkTreeIter et al.
- Reformatted document structure: instead of one single chapter with lots of sections, have multiple chapters (this tutorial is way to big to become part of the Gtk+ tutorial anyway); enumerate chapters and sections.
- Expanded the section on tree view columns and cell renderers, with help of two diagrams by Owen Taylor (from the GUADEC 2003 Gtk+ tutorial slides).
10th December 2003
- Added more information about how to remove a single row, or more specifically, the n-th row of a list store
- Added a short example about how to pack icons into the tree view.
28th October 2003
- Editable cells will work fine even if selection is set to GTK_SELECTION_NONE. Removed sentences that say otherwise.
23rd October 2003
- fix 'jumpy' selections in custom model GtkTreeSortable interface implementation. gtk_tree_model_rows_reordered() does not seem to work like the API reference implies (see bug #124790)
- added section about how to get the cell renderer a button click happened on
- added section about editable cells with spin buttons (and a CellRendererSpin implementation to the examples)
10th October 2003
- make custom model GtkTreeSortable implementation emit "sort-column-changed" signal when sortid is changed
- fixed code typo in selection function section; added a paragraph about rule hint to 'make whole row coloured or bold' section
7th October 2003
- Reformatted source code to make it fit on pages when generating ps/pdf output
- Added link to PDF and docbook XML versions.