TextView collapsed on realize

This widget creating by application in runtime and sometimes looks like that

After focus on text input area, it becomes normal:

How to fix that? Maybe I forgot some realizing method to update dimensions?
Sometimes it released without any issues, and sometimes with incorrect TextView height until I start enter some text or just grab the focus on this area.

Hi,

You may want to set a minimal height to the textview widget:

gtk_widget_set_size_request (GTK_WIDGET (textview), -1, 24);

That said, it should at least request the height of a single line I think…
I remember about a similar report in Gtk.TextView like row of Gtk.ListView does not expand (#635) · Issues · GNOME / pygobject · GitLab , seems that at init the textview doesn’t recompute its size by itself. It’s probably because textviews are usually placed in ScrolledWindows, so follow the allocated size instead of claiming it.

What happens if you call gtk_widget_queue_resize () on the textview? If it doesn’t help, then probably it’s just because it doesn’t have anything to display (some text or a cursor), so just stays flat.

1 Like

Already tried gtk_widget_queue_resize but no success.

I have following construction in Rust, where also grab focus on realize event

text_view.connect_realize(|this| {
    this.queue_resize();
    this.grab_focus();
});

grab_focus works here (even does not blinking until I click the area with mouse) thoughts maybe I can append some char to the buffer, then delete it…

UPD. only gtk_widget_set_size_request works, thank you

1 Like

Yes, I was the one who created that topic. So far I haven’t found a good solution, the solution you suggested to me works in the minimum example I posted but doesn’t work in my general code. I ended up giving up on the app I was writing. The reason for giving up was not only this bug but it contributed a lot to it.

1 Like

Thanks for the feedback. Sad to hear it did not worked :frowning:

From my experience, scrollable widgets like TextView or TreeView only properly size when put as direct child of a ScrolledWindow.
Probably with vscrollbar-policy=NEVER and hscrollbar-policy=AUTOMATIC (mandatory for word-wrapping) for this kind of usecase.

1 Like