tags:

views:

102

answers:

1

How to copy or duplicate gtk widgets? In my application I have one huge GtkComboBox created with one long for loop which eats up so much of time and I am using this combo at two places in one single screen.

So, what I want to do is create this combo for one time and duplicate/copy it in another one so it will save my time.

If I try to add same combo box pointer two times, gtk gives me error "child->paren != NULL" cause in gtk widget can have only single parent.

So what to do?

+2  A: 

This is why many widgets in GTK+ that show data are based on models. The model holds the data, not the widget. A widget acts as a "view" into the data, and models can be shared between several widgets.

You just need to use the same model in both combo boxes:

GtkListStore *model;
GtkWidget *c1, *c2;

/* Set up the model. */
model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INTEGER); /* Or whatever. */

/* Create first combo. */
c1 = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));

/* Create second combo. */
c2 = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
unwind
So i need to create GtkListModel and then create 2 separate comboboxes with this model. but while creating model i have used these function calls cell = gtk_cell_renderer_pixbuf_new();gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), cell, FALSE);gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), cell, "pixbuf",0, NULL);We need to use combo_box pointer for `gtk_cell_layout_set_attributes` and `gtk_cell_layout_pack_start` function calls while creating list model. how to deal with this, can you provide one example for this. i have 2 columns in drop down list text and image.
PP
@PP: None of those calls touch the model, so there's no problem. You are going to need to duplicate the code to build the customized renderer, but you should still be able to re-use the model.
unwind
Thanks... it works
PP