如何设置pygtk树形视图中单个单元格的颜色?
我有一个包含几列的 PyGtk 树视图。在运行时我不断添加新行。每个单元格包含一个字符串。通常,我会为每一行使用 gtk.CellRenderer,但我想根据单元格内的值设置每个单元格的背景颜色。
我尝试了几种解决方案,但似乎我必须为每个单元格创建一个 CellRenderer ,设置文本属性和背景颜色。这看起来有点过大,所以我问自己是否有更好的解决方案来解决这个问题。有什么建议吗?
I have a PyGtk treeview with a couple of columns. During runtime i add constantly new rows. Each cell contains a string. Normaly, i would use a gtk.CellRenderer
for each row, but I want to set the background color of each cell, according to the value inside the cell.
I tried a couple of solutions, but it seems that I have to create a CellRenderer
for each cell, set the text attribute and the background color. This seems a little oversized, so i asked myself if there is a nicer solution for the problem. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在树视图数据源的额外字段中定义树视图单元格的背景和前景。然后为树视图列设置前景和背景属性,以从相应的数据源字段获取它们的值。
下面是一个小例子:
希望这有帮助,问候
You can define background and foreground for your treeview cells in extra fields of the treeview data source. Then setup foreground and background attributes for the treeview columns to get their values from the corresponding data source fields.
Below is a small example:
hope this helps, regards