How to properly combine width setting and alignment for text label?

It seems that gtk_label_set_width_chars() disables horizontal alignment which set with gtk_widget_set_halign(). Removing gtk_label_set_width_chars() returns that horizontal alignment.
Is there a way to set both (width and h.alignment) for GTK label?

p.s. GTK4

set_width_chars() will set a minimum width for your Label.
But by default the text itself will still be centered.

You can use gtk_label_set_xalign() to align the text within the widget’s allocation.

1 Like

Additionally, you may need to set the GtkWidget:hexpand property on the label in order to tell the label’s parent to allocate extra room for it.

1 Like

it works with halign combining:

alignment to left:
gtk_widget_set_halign(, GTK_ALIGN_START) + gtk_label_set_xalign(, 0)

alignment to right:
gtk_widget_set_halign(, GTK_ALIGN_END) + gtk_label_set_xalign(, 1)

Thank you very much, that what I wanted to achieve

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.