GNOME Bugzilla – Bug 733981
Label with GTK_ALIGN_START does not work when width set by SizeGroup
Last modified: 2015-08-28 20:14:23 UTC
gupnp-universal-cp has some labels that should be left aligned and should all have the same width. A GtkSizeGroup is used to achieve the sizing (because the labels don't all have the same parent). Unfortunately this seems to break alignment. Below is example code to demonstrate: the labels align horizontally roughly in the middle even though I ask for GTK_ALIGN_START. /* gcc `pkg-config --libs --cflags gtk+-3.0` label-align-test.c */ #include <gtk/gtk.h> int main(int argc, char **argv) { GtkSizeGroup *group; GtkWidget *window, *grid, *label1, *label2; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (window), grid); label1 = gtk_label_new ("label 1"); gtk_widget_set_halign (label1, GTK_ALIGN_START); gtk_grid_attach_next_to (GTK_GRID (grid), label1, NULL, GTK_POS_BOTTOM, 1, 1); label2 = gtk_label_new ("label 2 with longer text"); gtk_widget_set_halign (label2, GTK_ALIGN_START); gtk_grid_attach_next_to (GTK_GRID (grid), label2, label1, GTK_POS_BOTTOM, 1, 1); group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); gtk_size_group_add_widget (group, label1); gtk_size_group_add_widget (group, label2); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show_all (window); gtk_main (); return 0; } If I remove the sizegroup the labels align to start as they should. Also, if I add a new container parent for each label and put the labels in the size group, things work as expected.
(In reply to comment #0) > If I remove the sizegroup the labels align to start as they should. Also, if I > add a new container parent for each label and put the labels in the size group, > things work as expected. Was supposed to say "Also, if I add a new container parent for each label and put the _containers_ in the size group, things work as expected.
You still need to add gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5), unfortunately.
Starting from GTK+ 3.16, you can use gtk_label_set_[xy]align() instead of using GtkMisc.
Don't think there is anything for us to fix here.