Oistein Aanensen wrote:
On Tue, 2003-01-14 at 09:44, James Henstridge wrote:Attached is a simple example that displays each cell in the tree view in different colours, based on data in the tree model.
Omar Kilani wrote:Hi,
Hello,Simply create a column in your model of type string which contains the colour you want for the cell. Then when setting up the tree view column, map that column to the "cell_foreground" or "cell_background" properties of the cell renderer.
I was wondering if someone could advise on a way of doing conditional
colouring of cells. Say I have:
-----|------|
one | four |
-----|------|
two | five |
-----|------|
three| six |
And I wanted to give each cell a different colour (based on its contents
or cell data.) How would I do it?
CellRendererText seems to apply the background/foreground colours to the
whole column.
Do I need to implement my own cell renderer?
I may be able to do it with treeview.get_cell_area, but I'm not sure how
to pass in the GdkRectangle argument.
I wondered about the same thing some weeks ago. Sorry for being silly,
but I don't understand how that method is going to give you different
colors in individual cells and not just alter the colors in different
columns.
James.
--
Email: [EMAIL PROTECTED] | Linux.conf.au http://linux.conf.au/
WWW: http://www.daa.com.au/~james/ | Jan 22-25 Perth, Western Australia.
import gtk
rows = [ ('foo', 'red', 'bar', 'blue'), ('baz', 'green', 'foo', 'yellow'), ('bar', 'orange', 'baz', 'magenta') ] # set up the data in the model model = gtk.ListStore(str, str, str, str) for row in rows: iter = model.append() model.set_value(iter, 0, row[0]) model.set_value(iter, 1, row[1]) model.set_value(iter, 2, row[2]) model.set_value(iter, 3, row[3]) win = gtk.Window() win.set_title('Tree cells') win.connect('destroy', gtk.mainquit) swin = gtk.ScrolledWindow() swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) win.add(swin) treeview = gtk.TreeView(model) # assign model column 0 to the "text" property, and # column 1 to the "cell_foreground" property. cell = gtk.CellRendererText() column = gtk.TreeViewColumn('Column 1', cell, text=0, foreground=1) treeview.append_column(column) cell = gtk.CellRendererText() column = gtk.TreeViewColumn('Column 2', cell, text=2, foreground=3) treeview.append_column(column) swin.add(treeview) win.show_all() gtk.main()