How to copy or duplicate gtk widgets?

How to copy or duplicate gtk widgets? In my application, I have one huge GtkComboBox created with one long loop that takes so long and I use this combo in two places on the same screen.

So, I want to do this combo at a time and duplicate / copy it to another so that it saves my time.

If I try to add the same pointer with the list twice, gtk will give me the error "child-> paren! = NULL", because there can only be one parent in the gtk widget.

So what to do?

+4
source share
1 answer

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

You just need to use the same model in both lists:

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)); 
+4
source

Source: https://habr.com/ru/post/1307039/


All Articles