I'm catching the "edited" signal of my GtkCellRenderer:
GtkTreeModel * sortmodel; // contains a sorted model of GtkListStore
// ...
GtkCellRenderer * renderer;
// ...
g_object_set(renderer, "editable", TRUE, NULL);
g_signal_connect(renderer, "edited",
G_CALLBACK(onEdited_name), sortmodel);
I'd now like to change the content of the cell accordingly, but I don't find any function, that would change the content of a cell of a GtkTreeModel.
void onEdited_name(GtkCellRendererText *cell,
gchar * path_string,
gchar * new_text,
gpointer treemodel)
{
GtkTreeModel * model = GTK_TREE_MODEL(treemodel);
GtkTreeIter iter;
gtk_tree_model_get_iter_from_string(model, &iter, path_string);
// TODO: set the value according to iter.
// gtk_list_store_set will not work of course, because
// we're operating on a GtkTreeModel
}
This question is related to: Changing the content of a GTK Tree View
Your first code snippet is correct.
Theory - Good to know
Gtk hierarchy
The following picture shows the GtkTreeModel hierarchy and what (important) functions they offer
As you can see, if you want to change the values of cells, you need to differentiate what kind of model you're actually working on.
GtkCellRenderer and the "edited" signal / callback
One Renderer should only be "assigned" to one column. Otherwise you don't know which column the user tried to change.
Change value of a GtkTreeModelSort of a GtkTreeStore
See the example below for GtkListStore, and replace GtkListStore with GtkTreeStore. That should hopefully do the trick.
Change value of a GtkTreeModelSort of a GtkListStore
Change value of a GtkListStore OR GtkTreeModelSort of GtkListStore
Imagine you have two GtkTreeViews shown based on the same model. One is sorted, the other one not. This function will show you how to manage those.
Note, that we now pass a GtkTreeView as gpointer, instead of GtkTreeModel.
This is a fully functional example code for a sorted model