使用python在GtkTreeview中更改选定的项目颜色 [英] Changing the selected item colour in a GtkTreeview using python

查看:501
本文介绍了使用python在GtkTreeview中更改选定的项目颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框,其中包含一个pygtk.treeview,用于按优先级列出任务。每行都有基于该优先级设置的背景色,例如最高优先级的背景为浅红色。



行选择颜色不容易改变。我可以使用> treeview.modify_base(gtk.STATE_SELECTED,#C4C4C4)来设置它,但是没有颜色可以很好地用于增强优先级概念的颜色。 p>

我的想法是将选择颜色更改为普通行背景颜色的稍暗版本,因此在上面的示例中,这将是较暗的红色。我试着调用上面的函数来响应treeselection的 changed 信号,它可以工作,但是闪烁频繁。



另一个想法是将选择更改为透明,并在其周围放置边框,但据我所知,这是不可能的。


  1. 如何以上述方式更改选择颜色而不闪烁?

  2. 我可以更改显示选区的方式吗?

注意:我知道这违反了用户选择的主题。我觉得我有一个很好的理由。具有颜色指示的优先级使其可以立即识别。选择颜色隐藏了这一点。如果您有其他建议,我会向他们开放,但它需要保持用户可以轻松识别优先级。

解决方案

您可以在最左边添加一个单独的pixbuf单元格(比如,尺寸与小图标相同)以指示选择。选定的行可以填充用于背景颜色的更纯(饱和)版本。例如。如果您为高优先级使用粉红色背景,则可以使用红色作为选择指示符。或者您可以使用图标。



使用颜色填充方法实现此功能:


  1. 根据Tobias的建议禁用内置高亮显示(使STATE_SELECTED颜色与STATE_NORMAL相同)。 根据 gtk.gdk.Pixbuf ,它允许您可以使用 fill 方法。

  2. 使用 CellRendererPixbuf 为您的选择单元格。

然后,您可以在选择更改时对选择单元格进行着色或取消着色,以指示选择了哪一行,或者显示一个图标(例如股票象征l)。



请注意,我没有实现这个,这只是一个想法。它明显偏离了通常的GTK选择指示,所以(显然)使用您的判断来判断它是否可用。


I have a dialog which contains a pygtk.treeview for listing tasks by priority. Each row has the background colour set based on that priority, so for example the highest priority has a light red background.

The row selection color is not so easy to change. I can set it using treeview.modify_base(gtk.STATE_SELECTED, "#C4C4C4"), but no colours work well with the colours used to enhance the concept of priority.

I had the idea to change the selection colour to be a slightly darker version of the colour used as the normal row background, so in the example above, that would be a darker red. I tried calling the function above in response to the treeselection's changed signal, and it works, but with heavy flickering.

Another idea was to change the selection to transparent and put a border around it instead, but as far as I can tell, this isn't possible.

  1. How can I change the selection colour in the way described above without the flickering?
  2. Can I change show the selection by having only a border around the row?

Note: I'm aware that this violates the theme selected by the user. I feel I have a good reason for it. Having the priority indicated by colour makes it instantly recognisable. The selection colour hides this. If you have alternative suggestions, I am open to them, but it needs to retain the ease at which a user can identify the priority.

解决方案

You could add a separate pixbuf cell (say, the same size as a small icon) to the far left to indicate selection. Selected rows could fill this with a more "solid" (saturated) version of the colour used for the background. For example. if you use a pink background for high priority, you could use red for the selection indicator. Or you could use an icon.

To implement this with the colour filling method:

  1. Disable the built-in highlighting as per Tobias' suggestion ("make the STATE_SELECTED color identical to STATE_NORMAL").
  2. Create a widget based on gtk.gdk.Pixbuf that allows you to create a solid area of colour, perhaps using the fill method.
  3. Use a CellRendererPixbuf for your "selection" cell.

You can then color or uncolour the "selection cell" upon selection changes to indicate which row is selected, or display an icon (eg. a stock symbol).

Note that I haven't implemented this, it's just an idea. It departs significantly from the usual GTK selection indication, so (obviously) use your judgement as to whether it's useable.

这篇关于使用python在GtkTreeview中更改选定的项目颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆