如何将GtkWidget添加到GtkToolbar?

时间:2012-05-24 15:52:24

标签: c gtk

我想将GtkEntry小部件插入GtkToolbar。以下行

gtk_toolbar_insert(GTK_TOOLBAR(searchPanel_Toolbar),
                      GTK_TOOL_ITEM(searchPanel_Entry), -1);

给了我这个错误:

Gtk-CRITICAL **: gtk_toolbar_insert: assertion `GTK_IS_TOOL_ITEM (item)' failed

如何在不使用gtk_toolbar_insert_widget()的情况下将小部件添加到GtkToolbar?

1 个答案:

答案 0 :(得分:2)

GtkToolbar *toolbar = gtk_toolbar_new();
GtkToolItem *item  = gtk_tool_item_new();
GtkEntry *entry = gtk_entry_new();

gtk_container_add( GTK_CONTAINER(item), GTK_WIDGET(entry) );
gtk_toolbar_insert( GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1 );