Re: Setting a Tree View Cell to insensitive and uneditable



From: "dhk", Date: 20/04/2010 09:46:

On 04/19/2010 01:34 PM, Nicolas Soubeiran wrote:
When creating your model set a specific column with a boolean property.
gtk_list_store_new(N_COLUMN, G_TYPE_STRING, G_TYPE_BOOLEAN);

Then in the treeview create a column using
gtk_tree_view_column_new_with_attributes("title", text_cell,"string",
STRING_COLUMN, "editable", EDITABLE_COLUMN, NULL);

Both replies seem to be saying the same thing, but I still don't
understand why the attribute values need to be stored in other columns.
Also I don't see how storing the attributes in other columns affect an
individual cell.

They are.  That is the typical way of doing it.  ANY table column (as long as it's the right type) can be 
linked to ANY attributes of ANY cells in that row (note the plurals - the mapping is essentially restricted 
only by value type).  Notice also that for a column showing a text string, the text shown in that column is 
just another attribute of the cell, as is its colour, font, editability, whatever.  A value in a table can 
also be linked to any compatible attriute of any one of the cells in the table, or even several attributes of 
the same cell.  So you could have a cells editability controlled by a table column, and in the very next cell 
be showing true/false whether the previous cell is editable, from the same table value, or two boolean 
attributes of a single cell controlled from the same table value, etc.


So this is the way to control the editability and sensitivity of a
single cell without changing the cells above and below the cell in the
same column. Does this apply for all attributes?

There is also another method of controlling cell attributes.  For every row, an optional function will be 
called (I forget the name off-hand).  But this function is called once per row, and can extract information 
from the table, and set the attributes of however many of the cells as it wishes.  I've used that a couple 
times particularly where I woul have to have several values in the table to accomplish one task, such as a 
colour, boolean and integer field, all to reflect one property.  Instead I've set the row function to read 
the single boolean field, and set the relevant cell attributes accordingly.

But for something simple like editability, using a table columns is certainly simpler, and probably more 
understandable also.


As I understand it, Gtk essentially iterates over the list of attribute/value linkages, which are nothing 
more than "for row number n, place the value of table column x, into attribute y of tree view cell z", 
blindly and faithfully performing each value copy in turn, per row of your tree view.  Any attribute you 
don't set, will remain as it was at the time that cell renderer was established.  Likewise there's nothing at 
all stopping you from setting one cell attribute more than once (pretty useless), or setting several 
attributes to one value (often quite useful).  The row function is simply another way of doing this same job, 
except that you do the value copying yourself, ie. fetch the table value (or any other value), and you set 
the relevant cell attributes from it as you see fit.


Fredderic



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]