2015-01-10 84 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);