Whenever I have a Gtk.Box
with a Gtk.TextView
inside, the text view is not displayed correctly until I resize the window.
Here are screenshots of an example:
Let me show you a minimal reproducible example with a Gtk.Box
containing a Gtk.TextView
directly as the child of a window (UI description in Blueprint):
template $ExampleWindow : Adw.ApplicationWindow {
Box {
orientation: vertical;
TextView { }
}
}
When I open the window, no text view is visible. It appears after changing the window size.
Kripto suggested in his answer to set the vexpand
of the Gtk.TextView
to true
. That solves the problem, but I want the text view to stay as small as possible (e.g. one line for one or no line of text, two lines for two lines of text, three for three, etc.), and not to expand vertically. After resizing the window manually, it works as expected.
Kripto just wrote a comment which answers my question:
What resolved it for me was adding a height-request to Gtk.TexView, after which it started displaying normally.
I changed the minimal reproducible example in Blueprint to this:
template $ExampleWindow : Adw.ApplicationWindow {
Box {
orientation: vertical;
TextView {
height-request: 20;
}
}
}
The text view now appears with the specified height and then expands when I add lines to the text in the text view.