Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The appropriate combination of GTK widgets for creating a column of widgets with scroll functionality is to use a GtkScrolledWindow with a GtkBox inside it.

The GtkBox can be set to have a vertical orientation and than widgets (such as GtkLabel, GtkButton etc.) can be packed inside it. The GtkScrolledWindow can be set to display the contents of the GtkBox inside it and also provide scrollbars if the contents exceed the size of the window.

Here is an example code snippet:

// Create a GtkScrolledWindow
GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);

// Create a GtkBox and set it to have a vertical orientation
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);

// Add widgets to the box
GtkWidget *label1 = gtk_label_new ("Label 1");
GtkWidget *button1 = gtk_button_new_with_label ("Button 1");
GtkWidget *label2 = gtk_label_new ("Label 2");
GtkWidget *button2 = gtk_button_new_with_label ("Button 2");
gtk_box_pack_start (GTK_BOX (box), label1, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), button1, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), label2, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), button2, FALSE, FALSE, 0);

// Add the box to the scrolled window and set it to be displayed
gtk_container_add (GTK_CONTAINER (scrolled_window), box);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

// Add the scrolled window to your main window
gtk_container_add (GTK_CONTAINER (main_window), scrolled_window);