Hi,
I want to have a single row cursor in a treeview, I’ve thought I could use a CellLayoutDataFunc to change background color only under cursor. I’ve tried this code but I’ve got segfault and I dont understand why…
Where am I wrong ?
I’ve got this error too : gtk_tree_model_get_path: assertion ‘GTK_IS_TREE_MODEL (tree_model)’ failed
Thanks for advices
public class Application : Gtk.Application {
Gtk.ListStore store = null;
Gtk.ApplicationWindow win;
Gtk.TreeView view;
public Application () {
Gtk.TreeIter iter;
store = new Gtk.ListStore (2, typeof(string), typeof(string));
store.append (out iter);
store.set (iter, 0, "A", 1, "10");
store.append (out iter);
store.set (iter, 0, "B", 1, "30");
store.append (out iter);
store.set (iter, 0, "C", 1, "50");
store.append (out iter);
store.set (iter, 0, "D", 1, "60");
}
protected override void activate () {
win = new Gtk.ApplicationWindow(this);
win.title = "TestApp";
win.window_position = Gtk.WindowPosition.CENTER;
win.set_default_size (800, 600);
view = new Gtk.TreeView.with_model (store);
Gtk.CellRendererText cell = new Gtk.CellRendererText ();
Gtk.TreeViewColumn col = new Gtk.TreeViewColumn.with_attributes ( "Value", cell, "text", 0);
col.set_cell_data_func (cell, (Gtk.CellLayoutDataFunc)render_value);
view.append_column (col);
col = new Gtk.TreeViewColumn.with_attributes ( "Text", cell, "text", 1);
col.set_cell_data_func (cell, (Gtk.CellLayoutDataFunc)render_value);
view.append_column (col);
win.add(view);
win.show_all();
}
public void render_value (Gtk.TreeViewColumn column, Gtk.CellRendererText
cell, Gtk.TreeModel model, Gtk.TreeIter iter) {
Gtk.TreePath? path = null;
Gtk.TreeViewColumn? focus_column = null;
if (model == null)
print ("null\n");
else {
print ("not null\n");
// path = store.get_path(iter); //gtk_tree_model_get_path: assertion 'GTK_IS_TREE_MODEL (tree_model)' failed
path = model.get_path(iter); // segfault
print ("segfault ?\n");
}
}
public static int main (string[] args) {
Gtk.init (ref args);
Application app = new Application ();
return app.run();
}
}