GTK C如何将滚动窗口添加到vbox

时间:2015-01-10 17:45:39

标签: c ubuntu gtk gnome gtk2

我无法将滚动窗口放入main_v_box,有什么问题?我只看到这个奇怪的橙色条状。当我将光标移动到它上面时,会出现水平滚动但我看不到文字。提前致谢。 enter image description here

  //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);

1 个答案:

答案 0 :(得分:2)

我再次尝试使用图像小部件,现在它可以工作了。谢谢你的回复。

//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);