How to debug widget sizing problems

I have a TextView widget whose size, first time it gets to show something, after its creation appears to be one of two possibilities. One at the expected size and another about 2.5 times as large. If I just create the text view widget and not write to it, the widget and the box it lives in remains unscaled. The probalbility of “wrong” size is about 50%. Afterwards, the box can be manually reduced to its intended size and subsequent updates of the widget will not resize it.

Does not matter if I write a const char[] to it using:
gtk_text_buffer_set_text(gtk_text_view_get_buffer(“const_text_string”);

or what I usually do,
gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
gtk_text_buffer_begin_irreversible_action(buffer);
gtk_text_buffer_insert_markup(buffer, &iter, markup, -1);
gtk_text_buffer_end_irreversible_action(buffer);

Same problem. Seems to be a race condition, I guess, but how to I get closer to what is the problem? This widget lives inside a layer of GtkBox:es, horizontal and vertical, that’s all.

(GTK4, ubuntu 23.04, libgtk-4.so.1.1000.4)

I found at least a work around for my sizing problem by assigning some text to the text view buffer associated with the text view. Not sure why but the textview vidget no longer resizes.

TextViews sometimes do weird size requests, depending on their content. The best way to mitigate this is to always pack TextViews into a ScrolledWindow.

If you activated text wrapping, also make sure to set scrolling policies to automatic.

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