Remove GTK + child containers, populate them, and then upgrade

I have a problem with the GTK + C application. I have a container that contains a button when the application starts. During operation, user intervention should make this widget contain more of them.
I need to write a function that removes all the "old" internal buttons, and then adds everything from the list and finally updates the view. This is what I am writing, but some parts are missing (TODO)

void refresh_sequence_panel() 
{
    GSList* iterator = NULL;
    GtkWidget* button;

    // TODO: Here the container must be empty

    // Now add all the buttons
    for (iterator = steps; iterator; iterator = iterator->next) {
       button = gtk_button_new_from_stock(GTK_STOCK_ADD);
       gtk_widget_set_size_request(button, SEQ_BUTTON_W, SEQ_BUTTON_H);
       gtk_box_pack_start(GTK_BOX(sequence_panel), button, FALSE, FALSE, 5);
       handler_id = g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(seq_popup), GTK_BOX(sequence_panel));
    }

    // TODO: Now refresh the view, so I can see the changes...
}

Hope someone can help, thanks!

+5
source share
3 answers

Removing all children:

GList *children, *iter;

children = gtk_container_get_children(GTK_CONTAINER(container));
for(iter = children; iter != NULL; iter = g_list_next(iter))
  gtk_widget_destroy(GTK_WIDGET(iter->data));
g_list_free(children);

, , , ( gtk_container_remove()), , , , .

" ", . GTK + , , .

+10

, . gtkmm ++

Gtk::Box_Helpers::BoxList *childList = &vboxImgLst->children();
Box_Helpers::BoxList::iterator start = childList->begin();
Box_Helpers::BoxList::iterator end = childList->end();

childList->erase(start, end);

vboxImgLst,

VBox *vboxImgLst;

, -, gtkmm ++.

0

( ):

Glib::ListHandle<Widget*> childList = this->get_children();
Glib::ListHandle<Widget*>::iterator it = childList.begin();

while (it != childList.end()) {
    remove(*(*it));
    it++;
}

(GTKMM 2.4)

0

All Articles