I have some code like this:
GtkWidget *scrollWin;
void appendDataToWindow(GtkWidget *widget, gpointer data)
{
GtkWidget *expander;
expander = gtk_expander_new("GET somepage.html 200 OK 100K");
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollWin),
expander);
}
int main()
{
// initialize a window
// add a vbox to th开发者_StackOverflow中文版e window
scrollWin = gtk_scrolled_window_new(NULL, NULL);
gtk_box_pack_start(GTK_BOX(vbox), scrollWin, FALSE, TRUE, 5);
// add a button to the vbox
// when the button is clicked, appendDataToWindow will be called
gtk_widget_show_all(window);
gtk_main();
return 0;
}
What I want to do is that when the button is clicked, a new GtkExpander will be added to the scrolled window, but it doesn't work.. Any suggestions will be helpful.
Maybe you're just missing some gtk_widget_show() calls
Looks good, but you seem to be missing the button creation:
GtkWidget *button;
button = gtk_button_new_with_label("Click me");
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(appendDataToWindow), scrollWin);
Add code to pack the button into your window as required, and then change the callback (appendDataToWindow
) to expect the scrolled window widget pointer in the data
argument, so that scrollWin
doesn't have to be a global.
精彩评论