Set the foreground color of the cellrenderertext when a row is selected.

When I have gtk.CellRendererText , I can associate its foreground color with one of the tree storage columns and set the foreground-set attribute to True to change the color of the text in this column. However, when a row with a color column is selected, its color disappears and matches any cell color selected. How to change the color when choosing it?

+3
python gtk pygtk gtktreeview
source share
1 answer

I had the same problem, and having tried different alternatives, using the markup property instead of the text property solved the problem. Below is an example and an example that works in Ubuntu Maverick:

 #!/usr/bin/python import gtk class Application(object): def __init__(self): window = gtk.Window() model = gtk.TreeStore(str) model.append(None, row=('Normal row',)) model.append(None, row=('<span foreground="red">Red row</span>',)) treeview = gtk.TreeView(model) renderer = gtk.CellRendererText() column = gtk.TreeViewColumn('Column', renderer, markup=0) treeview.append_column(column) scrolled_window = gtk.ScrolledWindow() scrolled_window.add(treeview) window.add(scrolled_window) window.connect('destroy', lambda w: gtk.main_quit()) window.show_all() def run(self): gtk.main() if __name__ == '__main__': Application().run() 

In a more complex tree structure with several columns that I'm working on, the markup property does not seem to work when no row is selected. Anyway, using both the markup and foreground properties at the same time seems to work fine.

+5
source share

All Articles