Ask Your Question
3

What combination of GTK widgets is appropriate for creating a column of widgets with scroll functionality?

asked 2021-04-09 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-01-22 11:00:00 +0000

woof gravatar image

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);
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-04-09 11:00:00 +0000

Seen: 12 times

Last updated: Jan 22 '22