[pygtk] TreeView - Making whole row colored

Stephen George steve_geo at optusnet.com.au
Thu Jan 31 14:50:16 WST 2008


Neil Dugan wrote:
> Stephen George wrote:
>> Hi,
>>
>> I am trying to get a treeview (with liststore model) to display rows 
>> in different colors based on content in the list.
>>
>> "The most suitable approach for most cases is that you add two 
>> columns to your model, one for
>> the property itself (e.g. a column COL_ROW_COLOR of type 
>> G_TYPE_STRING), and one for the boolean flag of
>> the property (e.g. a column COL_ROW_COLOR_SET of type 
>> G_TYPE_BOOLEAN). You would then connect these
>> columns with the "foreground" and "foreground-set" properties of each 
>> renderer. Now, whenever you set
>> a row’s COL_ROW_COLOR field to a colour, and set that row’s 
>> COL_ROW_COLOR_SET field to TRUE, then
>> this column will be rendered in the colour of your choice.
<snip>
>
> Hi Steve,
>
> I can't see the pattern in why the colors are how they are.  I think 
> some of the trouble has to be with some 'foreground-color' set as None.
>
> It would probably be better to not use the 'Modified' column to affect 
> the color, and just put the color you want the row in the 
> 'foreground-color' column (i.e. red,black or blue) and change the 
> set-up to.
>
> column.add_attribute(mycell, 'foreground', COLUMN_FOREGROUND)
> mycell.set_property('foreground-set', True)
>
<snip>
> Regards Neil.
Hi Neil,

Thanks for the reply.

I'm not sure whats happening, but it's not to do with 'foreground-color' 
set as None. ... I did a lot of testing before I started to introduce 
None for the color.
(According to pygtk reference None is the default value of that property)

I do have a system thats working for me now, .. but I suspect it only 
working because of some bug somewhere.

I totally ignore the foreground-set property, I never set it now, .. it 
seems to do nothing - set or not set

If I want to change the cells color, I put it in 'foreground-color' 
property, else I leave 'foreground-color' at None.

Thats it, .. it all works nicely like that. Ya, .. I know relying on 
undocumented behavior is bad, .. but I needed something that works now.

Cheers
Steve



More information about the pygtk mailing list