Size groups don't work with GtkScrolledWindow children (labels)
The size group is not applied when the widgets are part of scrolled windows. Here is an example of a vertical size group where the widgets don't have the same height (the label on the right does not get the height of the label on the left)
Steps to reproduce
- Run program below
- Attempt to scroll down on left side (OK, can scroll)
- Attempt to scroll down on right side (cannot scroll, size group isn't applied)
#include <gtk/gtk.h>
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
GtkWidget * box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 1);
gtk_widget_set_hexpand (box, true);
gtk_widget_set_vexpand (box, true);
GtkWidget * scroll1 = gtk_scrolled_window_new ();
gtk_widget_set_hexpand (scroll1, true);
gtk_widget_set_vexpand (scroll1, true);
GtkWidget * lbl1 = gtk_label_new ("ttest\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1test\n1est\n1");
gtk_scrolled_window_set_child (
GTK_SCROLLED_WINDOW (scroll1), lbl1);
gtk_box_append (GTK_BOX (box), scroll1);
GtkWidget * scroll2 = gtk_scrolled_window_new ();
gtk_widget_set_hexpand (scroll2, true);
gtk_widget_set_vexpand (scroll2, true);
GtkWidget * lbl2 = gtk_label_new ("test2");
gtk_scrolled_window_set_child (
GTK_SCROLLED_WINDOW (scroll2), lbl2);
gtk_box_append (GTK_BOX (box), scroll2);
GtkSizeGroup * sz_group = gtk_size_group_new (GTK_ORIENTATION_VERTICAL);
gtk_size_group_add_widget (sz_group, lbl1);
gtk_size_group_add_widget (sz_group, lbl2);
g_object_unref (sz_group);
gtk_window_set_child (GTK_WINDOW (window), box);
gtk_window_present (GTK_WINDOW (window));
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
Current behavior
The label on the right does not get the height of the label on the left, even though both labels are part of a vertical size group
Expected outcome
The 2 labels should have the same height
Version information
GTK 4.4.1 on Arch Linux
Additional information
You can see that there is a scrollbar on the left because the label is large but no scrollbar on the right because the size group doesn't get applied to that label
In my program, I have custom widgets instead of labels and I get some warnings about allocated sizes. I suspect this is the cause or at least related
Edited by alex-tee