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

时间:2023-01-24 16:20:49

I can't put scrolled window into main_v_box , what is wrong? I just see this little strange orange strip. When I move the cursor on it, horizontal scroll appears but I can't see text. Thanks in advance. GTK C如何将滚动窗口添加到vbox

我不能把滚动的窗口放到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);

1 个解决方案

#1


2  

I tried once again but with image widget and now it works. Thanks for replies.

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

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

#1


2  

I tried once again but with image widget and now it works. Thanks for replies.

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

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