GTK C 如何将滚动 window 添加到 vbox
GTK C how to add scrolled window to vbox
我无法将滚动的 window 放入 main_v_box 中,有什么问题吗?我只看到这个有点奇怪的橙色条带。当我将光标移到它上面时,会出现水平滚动条,但我看不到文字。提前致谢。
//formula_h_box
formula_h_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(main_v_box), formula_h_box, FALSE, FALSE, 0);
//formula_hscrollbar
formula_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(formula_scrolled_window), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
GtkWidget *view;
GtkTextBuffer *buffer;
view = gtk_text_view_new();
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
gtk_text_buffer_set_text (buffer, "HHello, this is some textHello, this is some textHello, this is some t\nextHello, this is some textHello, this is some textHello, this is some textHello, this\n is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello\n, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHell\no, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is som\ne textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textello, this is some text", -1);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(formula_scrolled_window), view);
gtk_box_pack_start(GTK_BOX(formula_h_box), formula_scrolled_window, TRUE, TRUE, 0);
//gtk_container_add(GTK_CONTAINER(formula_h_box), formula_scrolled_window);
我再次尝试使用图像小部件,现在可以使用了。感谢您的回复。
//formula_h_box
formula_h_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(main_v_box), formula_h_box, FALSE, FALSE, 10);
//formula_hscrollbar
formula_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(formula_scrolled_window), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
gtk_widget_set_size_request(formula_scrolled_window, 400, 200);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(formula_scrolled_window), image);
gtk_box_pack_start(GTK_BOX(formula_h_box), formula_scrolled_window, FALSE, FALSE, 0);
我无法将滚动的 window 放入 main_v_box 中,有什么问题吗?我只看到这个有点奇怪的橙色条带。当我将光标移到它上面时,会出现水平滚动条,但我看不到文字。提前致谢。
//formula_h_box
formula_h_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(main_v_box), formula_h_box, FALSE, FALSE, 0);
//formula_hscrollbar
formula_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(formula_scrolled_window), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
GtkWidget *view;
GtkTextBuffer *buffer;
view = gtk_text_view_new();
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
gtk_text_buffer_set_text (buffer, "HHello, this is some textHello, this is some textHello, this is some t\nextHello, this is some textHello, this is some textHello, this is some textHello, this\n is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello\n, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHell\no, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is som\ne textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textHello, this is some textello, this is some text", -1);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(formula_scrolled_window), view);
gtk_box_pack_start(GTK_BOX(formula_h_box), formula_scrolled_window, TRUE, TRUE, 0);
//gtk_container_add(GTK_CONTAINER(formula_h_box), formula_scrolled_window);
我再次尝试使用图像小部件,现在可以使用了。感谢您的回复。
//formula_h_box
formula_h_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(main_v_box), formula_h_box, FALSE, FALSE, 10);
//formula_hscrollbar
formula_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(formula_scrolled_window), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
gtk_widget_set_size_request(formula_scrolled_window, 400, 200);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(formula_scrolled_window), image);
gtk_box_pack_start(GTK_BOX(formula_h_box), formula_scrolled_window, FALSE, FALSE, 0);