How do I programmatically add a widget to a container created from GtkBuilder?
Posted
by Warner Young
on Stack Overflow
See other posts from Stack Overflow
or by Warner Young
Published on 2010-04-01T20:58:59Z
Indexed on
2010/04/01
21:03 UTC
Read the original article
Hit count: 179
I've created a window that has some containers and widgets in it, and I want to add a new widget dynamically at run-time to one of the Vboxes in this window. So I have this code, which brings up the window:
gtk_builder_add_from_file( g_builder, "window.xml", NULL );
mainwindow = GTK_WIDGET( gtk_builder_get_object( g_builder, "window" ));
gtk_widget_show( mainwindow );
Then I create a new label, for example, and add it to one of the existing Vboxes, called "vbox_mid", like this:
label = gtk_label_new( "Test label" );
vbox = GTK_WIDGET( gtk_builder_get_object( g_builder, "vbox_mid" ));
gtk_box_pack_end( GTK_BOX( vbox ), label, TRUE, TRUE, 0 );
But this doesn't seem to work. I don't see a new label in the vbox. I have a feeling I'm missing something here, but I can't see what it is. I thought perhaps there was a special GtkBuilder call to add a widget dynamically, but I don't see anything that looks like that. I would really appreciate any help on this.
© Stack Overflow or respective owner