Hi,

I want to change the background of an entire row in a TreeView.
Basically I want to make my own 'rule hint', but instead of every
other row I want to have bigger groups of rows with the same
background. For example a list with: 3 rows colour blue, then 2 rows
colour red, then 1 row colour blue, 5 rows colour red etc..

I tried setting the background of the CellRenderer, but that didn't
cover the whole row. Below is the code for a small example with just
one colour:

Does anybody know how to change background on the whole row?

/david
(disclaimer: I'm not really going to use red and blue, it's an example)

--------------------------------------------- >8
---------------------------------------------------------------------------

import pygtk
pygtk.require('2.0')
import gtk

#setup
win = gtk.Window()

model = gtk.TreeStore(str)
for i in range(3):
    itr = model.append(None,["Root Item %i" % i])
    for j in range(3):
        model.append(itr,["Leaf %i" % j])

tree = gtk.TreeView(model)
cell = gtk.CellRendererText()
col = gtk.TreeViewColumn('',cell)

#let's get a colour
back_colour = win.get_style().bg[0]

#define our own cell data func
def cell_func(column,cell,model,itr):
    txt = model.get(itr,0)[0]
    cell.set_property("background-gdk",back_colour)
    cell.set_property("text",txt)

col.set_cell_data_func(cell,cell_func)
tree.append_column(col)
win.add(tree)
win.connect('delete-event',lambda x,y:gtk.main_quit())
win.show_all()
gtk.main()
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to