gnope php gtk gui gnope.org  

GtkTreeView with icon/label tree

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
squirrel



Joined: 02 May 2006
Posts: 10
Location: Switzerland

PostPosted: Sun May 14, 2006 12:42 pm    Post subject: GtkTreeView with icon/label tree Reply with quote

This is a code example of a tree with an icon/label pair:
- First tree with two columns
- Second tree with two cells in one column

Took me a while to find out - may be of interest to others!

Code:

<?php

$window = new GtkWindow();

$icon_table = $window->render_icon(Gtk::STOCK_NO, Gtk::ICON_SIZE_SMALL_TOOLBAR);
$icon_column = $window->render_icon(Gtk::STOCK_YES, Gtk::ICON_SIZE_SMALL_TOOLBAR);

// create tree-model
$model = new GtkTreeStore(Gtk::TYPE_OBJECT, Gtk::TYPE_STRING);

$iter_table1 = $model->append(null, array($icon_table, 'user'));
$model->append($iter_table1, array($icon_column, 'user_id'));
$model->append($iter_table1, array($icon_column, 'username'));
$model->append($iter_table1, array($icon_column, 'password'));

$iter_table2 = $model->append(null, array($icon_table, 'person'));
$model->append($iter_table2, array($icon_column, 'person_id'));
$model->append($iter_table2, array($icon_column, 'name'));
$model->append($iter_table2, array($icon_column, 'prename'));

// treeview with 2 columns
$treeview1 = new GtkTreeView($model);

$col1 = new GtkTreeViewColumn('icon');
$col2 = new GtkTreeViewColumn('label');
$treeview1->append_column($col1);
$treeview1->append_column($col2);

$cell_renderer1 = new GtkCellRendererPixBuf();
$cell_renderer2 = new GtkCellRendererText();

$col1->pack_start($cell_renderer1, true);
$col2->pack_start($cell_renderer2, true);

$col1->set_attributes($cell_renderer1, 'pixbuf', 0);
$col2->set_attributes($cell_renderer2, 'text', 1);

// treeview with 2 cells in one column
$treeview2 = new GtkTreeView($model);

$col1 = new GtkTreeViewColumn('icon & label');
$treeview2->append_column($col1);

$cell_renderer1 = new GtkCellRendererPixBuf();
$cell_renderer2 = new GtkCellRendererText();

// 2 cells in one column!!
$col1->pack_start($cell_renderer1, false);
$col1->pack_start($cell_renderer2, false);

$col1->set_attributes($cell_renderer1, 'pixbuf', 0);
$col1->set_attributes($cell_renderer2, 'text', 1);

// build dialog
$hBox = new GtkHBox();

$window->add($hBox);
$hBox->pack_start($treeview1);
$hBox->pack_start($treeview2);

$window->show_all();
$window->connect_simple('destroy', array('Gtk', 'main_quit'));
gtk::main();

?>


Last edited by squirrel on Mon May 15, 2006 1:50 pm; edited 1 time in total
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Sun May 14, 2006 12:50 pm    Post subject: Reply with quote

If you know that the first column contains pixbufs only, you should do
Code:
new GtkTreeStore(GdkPixbuf::gtype, Gtk::TYPE_STRING);
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.