Reputation: 143
I have added txtview by using this function >>
text_v = gtk_text_view_new()
bt here scroll is not working and also how to set textview size, have used this one =>>
gtk_widget_set_size_request(text_v,400,200);
bt is also not working
Upvotes: 1
Views: 939
Reputation: 21955
This is the way I did it :
#include<gtk/gtk.h>
int main(int argc, char* argv[])
{
GtkWidget *textview, *window, *scrolledwindow;
GtkTextBuffer *buffer;
gtk_init(&argc, &argv); /*void gtk_init (int *argc,char ***argv);*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gchar* sample_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n" \
"sed do eiusmod tempor incididunt ut labore et dolore magna\n" \
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation\n" \
"ullamco laboris nisi ut aliquip ex ea commodo consequat.\n"\
"Duis aute irure dolor in reprehenderit in voluptate velit\n"\
"esse cillum dolore eu fugiat nulla pariatur. Excepteur sint\n"\
"occaecat cupidatat non proident, sunt in culpa qui officia\n"\
"deserunt mollit anim id est laborum.";
textview = gtk_text_view_new();
gtk_widget_set_size_request(textview, 400, 200); // This is but a request. The sizes are not guaranteed.
scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
gtk_text_buffer_set_text(buffer, sample_text, -1);
gtk_container_add(GTK_CONTAINER(scrolledwindow), textview);
gtk_container_add(GTK_CONTAINER(window), scrolledwindow);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
If you need to customize the scroll window it is worth having a look here.
Upvotes: 3