gtk : combo of pictures in a treeview
Question: I'm trying to make a combo box of pictures (as bellow) inside a treeview cell
to make a selection.

![enter image description here](http://i.stack.imgur.com/agLTj.png)

I tried to use a `cellRendererComboNew` to render the combo but the options to
fill the combobox `cellComboTextModel :=` work only for `String` and I can't
render pictures.

I tried to use a `cellRendererPixbufNew`. It render images but I can't perform
a selection on it.

What is the correct approach to make that?

An example in Haskell, Python, or in any language would be very helpfull.

Best regards.


Answer: In PyGobject I came up with this solution. The example is fully functional but
requires 2 png files in the same directory. I used two pngs with 100 x 20
pixel format.

The previous example used Gtk.ComboBox.new_with_model_and_entry() and I was
missing the set_entry_text_colum() function that has to go with such kind of
combobox.

    
    
    #!/usr/bin/python3
    
    from gi.repository import Gtk, Gdk, GdkPixbuf
    
    class ComboBoxWindow(Gtk.Window):
    
        def __init__(self):
            Gtk.Window.__init__(self, title="ComboBox Pixbuf Example")
    
            self.set_border_width(10)
    
            store = Gtk.ListStore(str, GdkPixbuf.Pixbuf)
            solid_line = GdkPixbuf.Pixbuf.new_from_file("solid_line.png")
            store.append(["1", solid_line])
            dashed_line = GdkPixbuf.Pixbuf.new_from_file("dashed_line.png")
            store.append(["2", dashed_line])
    
            vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
    
            combo = Gtk.ComboBox.new_with_model(store)
            rend_int = Gtk.CellRendererText()
            rend_pixbuf = Gtk.CellRendererPixbuf()
            combo.pack_start(rend_int, False)
            combo.add_attribute(rend_int, "text", 0)
            combo.pack_start(rend_pixbuf, True)
            combo.add_attribute(rend_pixbuf, "pixbuf", 1)
            combo.connect("changed", self.on_combo_changed)
    
            vbox.pack_start(combo, False, False, 0)
    
            self.add(vbox)
    
        def on_combo_changed(self, combo):
            tree_iter = combo.get_active_iter()
            if tree_iter != None:
                model = combo.get_model()
                row = model[tree_iter][0]
                print("Selected row {0}".format(row))
    
    win = ComboBoxWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()
    

![enter image description here](http://i.stack.imgur.com/4G06s.png)

Similar question:

  * [Show icon or color in Gtk TreeView tree](http://stackoverflow.com/questions/27745585/show-icon-or-color-in-gtk-treeview-tree)

Source:

  * <http://python-gtk-3-tutorial.readthedocs.org/en/latest/combobox.html>

