问题描述
当我有一个 gtk.CellRendererText
时,我可以将它的前景
颜色与其中一个树存储的列相关联,并将 foreground-set
属性设置为True,以更改该列中文本的颜色。但是,当选中具有彩色列的行时,其颜色消失,并且与任何选定单元格的颜色相同。如何选择颜色?
When I have a gtk.CellRendererText
, I can associate its foreground
color with one of the tree store's columns, and set the foreground-set
attribute to True, to change the color of the text in that column. However, when the row with the colored column is selected, its color disappears, and is the same as any selected cell's color. How do I change the color when it's selected?
推荐答案
我有同样的问题,并尝试不同的替代方案后,使用标记
属性而不是 text
属性解决了这个问题。请在下面找到适用于Ubuntu Maverick的示例:
I've had the same problem and, after trying different alternatives, using the markup
property instead of the text
property solved the problem. Please find below and 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 treeview with the multiple columns that I'm working on, the markup
property doesn't seem to work when the row isn't selected. Anyway, usage of both markup
and foreground
properties at the same time seems to work fine.
这篇关于突出显示行时设置cellrenderertext前景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!