开发者

How to get the control over the selection in a gtk.IconView?

I want to change the opacity or color of a gtk.IconView select box (I want actually to make the selection more visible).

I noticed that the gtk.IconView widget had style properties selection-box-alpha & selection-box-color but only accessible for reading.

The set_select_function() method of the gtk.TreeSelection class would have been use开发者_JAVA技巧ful to do what I want but it's used for a gtk.TreeView and I haven't found an equivalent for gtk.IconView

So, how can I do to have control over the selection and perform an action when the user select or unselect stuff ?

Edit : In fact, change the values of selection-box-alpha and selection-box-color style properties wouldn't be a solution. I don't really want to change the selection box opacity but the "opacity" of the pixbuf (by compositing with a color). So, I need an equivalent method of set_select_function for a gtk.IconView widget.


You might be able to set the pixmap opacity by implementing a custom gtk.CellRenderer that draws the pixmap according to the selection state, and replacing the gtk.IconView's default cell renderer with your own.


In fact, we need to replace the gtk.IconView's default cell renderer by gtk.CellRendererPixbuf which have follow-state property

We replace the default cell renderer by using the gtk.CellLayout class which gtk.IconView inherits.

model = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_STRING)
iconview = gtk.IconView(model)

renderer = gtk.CellRendererPixbuf()
renderer.set_property('follow-state', True)
iconview.pack_start(renderer)
iconview.set_attributes(renderer,pixbuf=1)  #pixbuf is the column number corresponding to the pixbuf to render in the model
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜