如何初始化GtkScrolledWindow以避免滾動條儘可能增長?使GtkScrolledWindow默認顯示所有子項
默認情況下,它似乎越小越好。
演示代碼(與SIGINT
退出):
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
GtkWidget* window;
GtkWidget* content;
GtkWidget* sw;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(window), sw);
gtk_widget_show(sw);
content = gtk_button_new_with_label("This is a very, very"
"very very very very very very very very long text");
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), content);
gtk_widget_show(content);
gtk_widget_show(window);
gtk_main();
return 0;
}
當然,這個工作,但它是一個醜陋的黑客攻擊,正如你所說,不除少數幸運的工作案例。而afaik你不能只是查詢一個GTK Widget的大小,你能嗎? – phihag 2009-01-21 04:21:11