开发者

How to copy or duplicate gtk widgets?

How to copy or duplicate gtk widgets? In my application I have one huge GtkComboBox created with on开发者_如何学编程e 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?


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));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜