how can i add images to ComboBox? I want to have text and at right image?
I have tried to implement it but well it did not work ^.^
Any advices needed
First you need a model to store items (text and images).
enum {COL_TEXT, COL_ICON, NUM_COLS};
GtkListStore *store = gtk_list_store_new( 2, G_TYPE_STRING, GDK_TYPE_PIXBUF );
/* add some data */
GtkTreeIter iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set( store, &iter, COL_TEXT, some_text, COL_ICON, some_pixbuf, -1 );
Next you create GtkComboBox
(or GtkComboBoxEntry
and you can skip creating text cell renderer).
// GtkComboBoxEntry *combo = gtk_combo_box_entry_new_with_model( GTK_TREE_MODEL(store), COL_TEXT );
GtkComboBox *combo = gtk_combo_box_new_with_model( GTK_TREE_MODEL(store) );
GtkCellRenderer *renderer;
/* text cell */
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(combo), renderer, TRUE );
gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(combo), renderer, "text", COL_TEXT, NULL );
/* icon cell */
renderer = gtk_cell_renderer_pixbuf_new();
gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(combo), renderer, FALSE );
gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(combo), renderer, "pixbuf", COL_ICON, NULL );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With