Re: glade + tree view
| From: | FOURTICQ Benjamin | Date: | Thu, 31 Aug 2006 11:39:31 +0000 |
| Subject: | Re: glade + tree view | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-7154@lists.php.net to get a copy of this message | ||
Hello,
you should try this (modified from the example in the php-gtk doc)
//the model
$store = new GtkListStore(Gtk::TYPE_BOOLEAN, Gtk::TYPE_STRING, Gtk::TYPE_LONG);
$treeview=$this->glade->get_widget("treeview1");
$treeview->set_model($store);
//add some data to the data store
$store->append(array(true , 'PHP' , 1994)); $store->append(array(true , 'C' , 1970)); $store->append(array(true , 'C++' , 1983));$store->append(array(false, 'Ruby' , 1995)); $store->append(array(false, 'Python' , 1990)); $store->append(array(true , 'Java' , 1994)); $store->append(array(false, 'Fortran', 1950)); $store->append(array(false, 'List' , 1958)); $store->append(array(false, 'Haskell', 1987)); $store->append(array(false, 'Eiffel' , 1985)); //sort by year by default $store->set_sort_column_id(2, Gtk::SORT_ASCENDING); //the text renderer is used to display text $cell_renderer = new GtkCellRendererText(); //Create the first column, make it resizable and sortable $colLanguage = new GtkTreeViewColumn('Language', $cell_renderer, 'text', 1); //make the column resizable in width $colLanguage->set_resizable(true); //make it sortable and let it sort after model column 1 $colLanguage->set_sort_column_id(1); //add the column to the view $treeview->append_column($colLanguage); //second column, also sortable $colYear = new GtkTreeViewColumn('Year', $cell_renderer, 'text', 2); $colYear->set_sort_column_id(2); $treeview->append_column($colYear); //we want to display a boolean value, so we can use a check box for display $bool_cell_renderer = new GtkCellRendererToggle(); $colUsed = new GtkTreeViewColumn('Used', $bool_cell_renderer, 'active', 0); $colUsed->set_sort_column_id(0); $treeview->append_column($colUsed); Hope this help... Benjamin. suomaf a écrit :
Hello all, Could someone show me how to poplulate the tree view in this glade file with a list of Strings of (This, treeview, thingy, is, hard). Also under properties for the tree view there is a place where we can set the TreeView Model, it opens up to "Choose a GtkTreeModel in this project" dialog, do I have to set anything there? Thank you for any help I can get. Suomaf my php file ================= <?php class loginClass extends GtkWindow {function __construct() { parent::__construct(); $this->glade = new GladeXML(dirname(__FILE__) . '/test.glade'); $this->glade->signal_autoconnect_instance($this); // $this->glade->get_widget("treeview1")-> ???? i know something goeshere but i am newbie =(}} $myClassInstance = new loginClass(); //Start the main loop Gtk::main() ?> my glade file ================= <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!-- Generated with glade3 --> <glade-interface> <widget class="GtkWindow" id="window1"><child> <widget class="GtkVBox" id="vbox1"> <property name="visible">True</property> <child> <widget class="GtkLabel" id="label1"> <property name="visible">True</property> <property name="label" translatable="yes">Test TreeView</property></widget> </child> <child> <widget class="GtkTreeView" id="treeview1"> <property name="visible">True</property> </widget> <packing> <property name="position">1</property> </packing> </child> <child> <widget class="GtkHButtonBox" id="hbuttonbox1"> <property name="visible">True</property> <child> <widget class="GtkButton" id="button1"> <property name="visible">True</property> <property name="label" translatable="yes">Ok</property></widget> </child> <child> <widget class="GtkButton" id="button2"> <property name="visible">True</property> <property name="label" translatable="yes">Clear</property> </widget> <packing> <property name="position">1</property> </packing> </child> </widget> <packing> <property name="position">2</property> </packing> </child> </widget> </child></widget> </glade-interface>