there is a code

GtkWidget *label = NULL; label = gtk_label_new(NULL); gtk_label_set_text(GTK_LABEL(label), "this is label"); 

and

 GtkWidget *textview = NULL; textview = gtk_text_view_new(); 

containers down

How to make a scroll bar for the label and textview , preferably a very simple example, please. I just can not understand how this is done.

  • textview does not receive a strip, but only expands the window - user245984

2 answers 2

 GtkWidget *scrolled_window = NULL; scrolled_window = gtk_scrolled_window_new(NULL, NULL); textview = gtk_text_view_new(); gtk_container_add(GTK_CONTAINER(scrolled_window), textview); // gtk_box_pack_start(GTK_BOX(hbox), scrolled_window, TRUE, TRUE, 5); 

    To get the scroll bars, you need to cram the widget into the GtkScrolledWindow .

     #include <gtk/gtk.h> int main( int argc, char *argv[]) { gtk_init(&argc, &argv); gchar *lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing\n" "elit, sed do eiusmod tempor incididunt ut labore et\n" "dolore magna aliqua. Ut enim ad minim veniam, quis\n" "nostrud exercitation ullamco laboris nisi ut aliquip\n" "ex ea commodo consequat. Duis aute irure dolor in\n" "reprehenderit in voluptate velit esse cillum dolore\n" "eu fugiat nulla pariatur. Excepteur sint occaecat\n" "cupidatat non proident, sunt in culpa qui officia\n" "deserunt mollit anim id est laborum.\n"; GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 600, 150); GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); GtkWidget* scrolledwindow_label = gtk_scrolled_window_new(NULL, NULL); GtkWidget *label = gtk_label_new(lorem); GtkWidget* scrolledwindow_text = gtk_scrolled_window_new(NULL, NULL); GtkWidget *textview = gtk_text_view_new(); gtk_text_buffer_set_text( gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)), lorem, -1); gtk_container_add(GTK_CONTAINER(window), hbox); gtk_container_add(GTK_CONTAINER(scrolledwindow_label), label); gtk_box_pack_start(GTK_BOX(hbox), scrolledwindow_label, 1, 1, 4); gtk_container_add(GTK_CONTAINER(scrolledwindow_text), textview); gtk_box_pack_start(GTK_BOX(hbox), scrolledwindow_text, 1, 1, 4); gtk_widget_show_all(window); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_main(); return 0; } 
    • mda ... less than a minute late ... =) delete later ... - Fat-Zer
    • Yes, they were late) Yes, you do not need to delete, it will be useful to someone. But thanks) - user245984