On Tue, 2010-06-15 at 11:24 +0200, Dominik Gabi wrote: > >> Is there an easier way to manipulate a TreeRow or am I just missing > >> something here? > >> > > > > Unfortunately Gtk::TreeView::get_column() returns a TreeViewColumn > whereas Gtk::TreeRow::operator[] takes an TreeModelColumn as argument. > I've solved the problem with the following code which is not as nice as > the book solution but works fine for now. You could have used the Gtk::TreeRow::operator[] as in the book if you had defined your own Gtk::TreeModelColumnRecord (see its docs[1]). For example, take a look at the small test (along with the glade file) I wrote to confirm my first answer. It uses a Gtk:ListStore for the model but it should show what I'm trying to explain. Hope it helps. [1] http://library.gnome.org/devel/gtkmm/2.90/classGtk_1_1TreeModelColumnRecord.html#_details -- José
#include <gtkmm.h> #include <iostream> class ModelColumns : public Gtk::TreeModelColumnRecord { public: ModelColumns() { add(id); add(name); } Gtk::TreeModelColumn<int> id; Gtk::TreeModelColumn<Glib::ustring> name; }; int main(int argc, char** argv) { Gtk::TreeView* treeview; Gtk::Main kit(argc, argv); ModelColumns columns; Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("liststore.glade"); builder->get_widget("treeview1", treeview); Glib::RefPtr<Gtk::ListStore> liststore = Glib::RefPtr<Gtk::ListStore>::cast_static(builder->get_object("liststore1")); if(!treeview || !liststore) { std::cerr << "Could not load treeview and liststore." << std::endl; return 1; } typedef Gtk::TreeModel::Children type_children; //minimise code length. type_children children = liststore->children(); for(type_children::iterator iter = children.begin(); iter != children.end(); ++iter) { Gtk::TreeModel::Row row = *iter; std::cout << row[columns.id] << " - " << row[columns.name] << "." << std::endl; } for(int i = 0; i < 3; i++) { Gtk::TreeViewColumn* column = treeview->get_column(i); if(!column) std::cout << "Could not get column #" << i << std::endl; else std::cout << "Column #" << i << "'s width = " << column->get_width() << std::endl; } }
Attachment:
liststore.glade
Description: application/glade