ich habe öfter diese Frage in Foren gesehen, aber nie eine Antwort, die es konkret löste, daher, falls es jemanden interessiert: Auf englisch, weil ich das auch in einem englischsprechenden Forum setze:
I found a way to make some cell editable or not, depending on the content of another cell:
The important command is “gtk_tree_view_column_add_attribute(column, renderer, "editable", COL_EDIT); “
It says that the attribute “editable” of the column value depends of the content of the column COL_EDIT
Name of the columns:
parameter name (COL_NAME)
parameter value (COL_VALUE)
parameter editable(COL_EDIT)
1) make the model of the treeview
Code:
pw_local.store = gtk_tree_store_new(COL_COUNT,G_TYPE_INTEGER, G_TYPE_BOOLEAN );
pw_local.model = GTK_TREE_MODEL(pw_local.store);
gtk_tree_view_set_model(GTK_TREE_VIEW(pw_local.treeview),pw_local.model);
usw...
2) make the column editable
Code:
g_signal_connect(G_OBJECT(renderer),"edited",G_CALLBACK(cb_function 2),NULL);
g_signal_connect(G_OBJECT(renderer),"editing-started",G_CALLBACK(cb_function 1),NULL);
3) make a column which will content a boolean value:
0 column is read only
1 column is editable
Code:
#define COLNAME 0
#define COL_VALUE 1
#define COL_EDIT 2
// parameter name
Code:
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("paramname",renderer,"text",COL_NAME,NULL);
gtk_tree_view_column_set_visible (column,TRUE);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview),column);
// parameter value
Code:
renderer = gtk_cell_renderer_text_new();
g_object_set(G_OBJECT(renderer),"editable",TRUE,NULL);
g_signal_connect(G_OBJECT(renderer),"edited",G_CALLBACK(cb_function2),NULL);
g_signal_connect(G_OBJECT(renderer),"editing-started",G_CALLBACK(cb_function1),NULL);
column = gtk_tree_view_column_new_with_attributes("value",renderer,"text",COL_VALUE,NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview),column);
_tree_view_column_add_attribute(column, renderer, "text", COL_VALUE); // make a renderer text
gtk_tree_view_column_add_attribute(column, renderer, "editable", COL_EDIT); //editable depends on the value in COL_EDIT
//editable or not
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("paramedit",renderer,"text",COL_EDIT,NULL);
gtk_tree_view_column_set_visible (column,TRUE);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview),column);
4) fill the tree
for each row:
Code:
gboolean cell_editable;
cell_editable = FALSE // or TRUE, if this row shoulb be editable
gtk_tree_store_append(pw_local.store, &child, &iter); append the new row
gtk_tree_store_set(pw_local.store, &child,
COL_NAME, “max speed”,
COL_VALUE, 1000,
COL_EDIT, cell_editable
,-1);
When you show the tree, in the rows where the last column contents “0” you can not edit the value. In the rows where the last column contents “1”, you can edit the row.
Lesezeichen