Is it possible to add a column to an existing treemodel in gtk?

I have a tree structure that is populated from a treemodel.

I would like to add colum to the tree structure. Is it possible to draw data for this column from a separate treemodel or can I add a runtime column to an existing treemodel?

+4
source share
3 answers

You can add as many columns to the tree view as you need, without restricting the columns of the model. If the required data is not available in the model, you can set a callback for the column:

import gtk def inIta(col, cell, model, iter, mymodel): s = model.get_string_from_iter(iter) niter = mymodel.get_iter_from_string(s) obj = mymodel.get_value(niter, 0) cell.set_property('text', obj) model = gtk.ListStore(str) model2 = gtk.ListStore(str) view = gtk.TreeView(model) rend1 = gtk.CellRendererText() col1 = gtk.TreeViewColumn('hello', rend1, text=0) view.append_column(col1) rend2 = gtk.CellRendererText() col2 = gtk.TreeViewColumn('ciao', rend2) col2.set_cell_data_func(rend2, inIta, model2) view.append_column(col2) model.append(['hello world']) model2.append(['ciao mondo']) win = gtk.Window() win.connect('delete_event', gtk.main_quit) win.add(view) win.show_all() gtk.main() 
+3
source

There is an gtk.TreeView method in the append_column , so yes, you can programmatically add a column to gtk.TreeView .

However, I don’t know a single method of adding a new column to an existing model or using multiple models for the same gtk.TreeView . In any case, I think you can create a new model with an additional column, copy the contents of the previous one and update the tree view to use the new model.

0
source

To answer the question in the title: No, you cannot add columns to GtkTreeModel after creating it.

0
source

Source: https://habr.com/ru/post/1391887/


All Articles