int main(int argc, char **argv)
{
GtkWidget *pWindow;
GtkWidget *pVBox;
GtkWidget *pEntry;
GtkWidget *pButton;
GtkWidget *pLabel;
GtkWidget *text_view;
GtkWidget *scrollbar;
gtk_init(&argc, &argv);
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(pWindow), "My IRC");
gtk_window_set_default_size(GTK_WINDOW(pWindow), 800, 600);
g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);
pVBox = gtk_vbox_new(TRUE, 0);
pEntry = gtk_entry_new();
pLabel = gtk_label_new(NULL);
text_view = gtk_text_new(NULL, NULL);
scrollbar = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(pWindow), pVBox);
gtk_box_pack_start(GTK_BOX(pVBox), scrollbar, TRUE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(pVBox), pEntry, TRUE, FALSE, 0);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollbar), text_view);
g_signal_connect(G_OBJECT(pEntry), "activate", G_CALLBACK(on_activate_entry), (GtkWidget*) text_view);
gtk_widget_show_all(pWindow);
gtk_main();
return EXIT_SUCCESS;
}
我想让text_view
框大于另一个框。我在GTK文档中找不到任何解决方案。
PS:这是GTK 2.0。
答案 0 :(得分:1)
gtk_box_pack_start()
的两个布尔参数是expand
和fill
。当expand
为真时,小部件在分配其他小部件后会获得额外的空间。如果fill
为真,则小部件调整大小以填充该空间。所以你要做的是
// expand AND fill - fills all available space
gtk_box_pack_start(GTK_BOX(pVBox), scrollbar, TRUE, TRUE, 0);
// NO expand AND NO fill - only uses what it needs
gtk_box_pack_start(GTK_BOX(pVBox), pEntry, FALSE, FALSE, 0);
Here's a page with more information.请注意,您可以将[hv](expand|align)
属性与框和网格一起使用(并使用gtk_container_add()
,其行为类似gtk_box_pack_start()
)。