GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Nov 27, 2014 12:10 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: how to change the "editable" property of a single cell
PostPosted: Fri Oct 26, 2012 11:04 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
Hello,

I made a treeview with 20 rows and 5 columns, only one column is editable.
But then, when I begin to fill the treeview with data, I would like to change the properties of some cells.
In the editable column some of them should be grey and not editable, depending on their content.
My questions:
1) Can I make it when I append a row with "gtk_tree_store_set(...)"
2) If not I would like to access the cell renderer after having filled the tree.
Can I get the cell renderer of a cell if I know its row and its column? or a path?

Thank you in advance

MBoerner

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_valueEdited),NULL); 
g_signal_connect(G_OBJECT(renderer),"editing-started",G_CALLBACK(cb_valueEdited_started),NULL); 
column = gtk_tree_view_column_new_with_attributes("value",renderer,"text",COL_VALUE,NULL);
gtk_tree_view_column_set_resizable(column,TRUE);
gtk_tree_view_append_column(GTK_TREE_VIEW(pw_local.treeview),column);


Top
 Profile  
 
 Post subject: solvedRe: how to change the "editable" property of a single
PostPosted: Wed Oct 31, 2012 7:21 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
I asked in many foren for a solution to make a cell in a treeview editable depending on its contents. I found a solution, maybe it is interesting for somebody else:


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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group