Frage

I'm investigating how to create in Python (2.7 or above) a GtkIconView that has a custom CellRendererText for the text element of the IconView.

The reason for this, is that I need to override certain properties during the iconview creation.

Looking around I found this example for PyGtk for TreeViews - similar but I need an Introspection example for an IconView

I've looked at the C++ documentation but I dont really understand how to assign a cellrenderertext to the IconView.

Again I've found some python documentation to create a custom cellrenderer for a treeview

Can anyone point me in the correct direction how to modify the example for an IconView

War es hilfreich?

Lösung 2

Gtk.IconView inherits from Gtk.CellLayout, so you can use the cell layout functions to replace the current text renderer. Something in the vein of:

renderers = iconview.get_cells()
iconview.clear()
for r in renderers:
    if not isinstance(r, Gtk.TextRenderer):
        iconview.pack_start(r)
    else:
        iconview.pack_start(my_custom_renderer)

I don't know if this works, but that's how I'd go about it.

Andere Tipps

The official way to go is to use set_cell_data_func.

However in the context of an IconView it is done differently to the TreeView case (where you simply pass the custom rendering function to a TreeViewColumn instance).

This had me confused too until I found this nugget in the GTK3 Ruby bindings where Kouhei Sutou demonstrates the use of the GtkCellLayout interface to set up cell renderers in an IconView.

NOTE: If you previously had setup your columns using setters such as iconView.text_column = TEXT_IDX, then you should remove them once your custom renderer is in place or you will see duplicate text labels.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top