2015-01-10 56 views
0

我不能把滚动窗口放入main_v_box,有什么错?我只是看到这个奇怪的橙色小条。当我移动光标时,出现水平滚动,但我看不到文字。提前致谢。 enter image description hereGTK C如何添加滚动窗口到vbox

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

究竟是什么问题,滚动的窗口不会填满窗口?如果是这样,盒子是窗户的直接孩子吗? – andlabs

+0

是的,我想看看按钮和条目下面的文本。我不知道盒子是否是窗口的直接子,我刚开始学习gtk +。我使用(gtk_box_pack_start)将一个盒子添加到另一个盒子,最后是“gtk_container_add(GTK_CONTAINER(window),main_space_h_30_box);” – jjpikoov

+0

我测试你的代码对我来说看起来很不错,也许你应该包括所有的代码来帮助你更好的,包括创建窗口和其他元素。我认为有些小部件没有扩展,但不清楚哪一个。 – alvaropg

回答

1

我试过一次,但与图像小部件,现在它的工作。感谢您的回复。

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