Many thanks! It seems that the following call was the key to my problem:
m_TextView.set_expand();
This call seems very non-intuitive to me; I would have expected the
TextView to automatically expand
based on the contents of the TextBuffer.

Or, to ask the question another way: Why does the TextView display
correctly when it is added as a
child of the window but not when it is placed in a Grid?



On Thu, Oct 6, 2022 at 9:42 AM Kjell Ahlstedt <kjellahlst...@gmail.com>
wrote:

> set_child(m_grid); shows that this is gtkmm4.
>
> I made some tests with the TextView example in gtkmm-documentation,
>
>
> https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/tree/master/examples/book/textview
>
> 1. Replaced Gtk::Box m_VBox; by Gtk::Grid m_grid; The TextView is a child
> of a ScrolledWindow, which is a child of the Grid, which is the child of
> the window.
> The text in the TextView was shown.
>
> 2. Removed the ScrolledWindow.
> The TextView was not shown. Or, rather, it was minimized.
>
> 3. Added m_TextView.set_expand();
> The TextView was shown again.
> Den 2022-10-06 kl. 13:00, skrev Rodolfo Ribeiro Gomes:
>
> If you are gtkmm3, widgets are hidden by default.
> You should call Gtk::Container::show_all_children() or
> Gtk::Widget::show_all().
>
> AFAIK, in gtkmm4 this isn't necessary anymore, as widgets are (finally)
> visible by default.
>
> Em qui., 6 de out. de 2022 às 07:33, Bill Greene via gtkmm-list <
> gtkmm-list@gnome.org> escreveu:
>
>> Thanks for taking a look at this.
>>
>> Unfortunately, even after I make the TextView   a class member, I still
>> don't see the text displayed in the window.
>> A concise description of the problem is this:
>> If I make the TextView a child of the window, the text is displayed. If I
>> make the TextView a child of a Grid, and the
>> Grid a child of the window, the text is not displayed.
>>
>> I am assuming there might be some property of the Grid I need to set?
>>
>> On Wed, Oct 5, 2022 at 12:40 PM Kjell Ahlstedt <kjellahlst...@gmail.com>
>> wrote:
>>
>>> You have declared the TextView  as a local variable in the constructor.
>>> It will be deleted when the constructor finishes. You must either
>>> declared it in your window class, like the buttons in
>>>
>>>
>>> https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/blob/master/examples/book/grid/examplewindow.h
>>>
>>> or create it with Gtk::make_managed() in the constructor, like the
>>> button in
>>>
>>>
>>> https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/blob/master/examples/book/scrolledwindow/examplewindow.cc
>>>
>>> Den 2022-10-05 kl. 17:00, skrev Bill Greene via gtkmm-list:
>>> > I am trying to add a TextView instance to a Grid. But when I display
>>> > the window, it is
>>> > empty. The Grid examples I have seen add buttons to the grid and these
>>> > work fine
>>> > for me. But I don't understand the difference between adding a button
>>> > and adding
>>> > a TextView. If anyone can help me with this, I would appreciate it.
>>> >
>>> > Here is my sample code (part of the constructor for my window):
>>> >
>>> >   set_child(m_grid);
>>> >   Gtk::TextView tc;
>>> >   Glib::RefPtr<Gtk::TextBuffer> tb = Gtk::TextBuffer::create();
>>> >   std::string msg("cell 1,1");
>>> >   auto it = tb->insert(tb->begin(), msg);
>>> >   tc.set_buffer(tb);
>>> >   m_grid.attach(tc, 0, 0);
>>> >   m_grid.set_visible();
>>> >
>>>
>>
>>
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to