gpt4 book ai didi

c GTK3 文本应向上滚动而不是隐藏

转载 作者:行者123 更新时间:2023-11-30 17:04:28 26 4
gpt4 key购买 nike

这是我的问题:我只是将 gtk_text_view_new() 放入 gtk_scrolled_window_new() 中。现在,当我在 textField 中写入时,在 gtk_widget_set_size_request->high 的末尾,文本被隐藏,并且整个文本不会按我想要的方式向上滚动。-> 文本字段应自动向上滚动并显示最后一行。

#include <gtk/gtk.h>


int main(int argc, char **argv) {

gtk_init(&argc, &argv);

GtkWidget *window;
GtkWidget *myGrid;
GtkWidget *scollwindow;
GtkWidget *textField;
GtkTextBuffer *buffer;
GtkWidget *quitbutton;

//---------------------widgets-------------------------------
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
quitbutton = gtk_button_new_with_label("QUIT");
myGrid = gtk_grid_new ();

//---------------------textField-------------------------------
textField = gtk_text_view_new ();
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textField));
gtk_text_buffer_set_text (buffer, "Hello, this is some text, ", -1);

//---------------------insert textField in scrollwindow-------------------------------

scollwindow = gtk_scrolled_window_new (NULL,NULL);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scollwindow), textField);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scollwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);

//---------------------widgets size-------------------------------
gtk_widget_set_size_request (scollwindow, 200, 200);
gtk_widget_set_size_request (window, 200, 200);

//---------------------grid attache-------------------------------
gtk_grid_attach(GTK_GRID(myGrid), scollwindow, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(myGrid), quitbutton, 0, 1, 1, 1);

//---------------------add to grid-------------------------------
gtk_container_add(GTK_CONTAINER(window), myGrid);

//---------------------signals-------------------------------
g_signal_connect(quitbutton, "clicked", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(window, "destroy", gtk_main_quit, NULL);

gtk_widget_show_all(window);

gtk_main();
return 0;
}

最佳答案

明白了,只需更改行“gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scollwindow), textField);”到“gtk_container_add(GTK_CONTAINER(scollwindow),textField);”

关于c GTK3 文本应向上滚动而不是隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35766396/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com