Re: Add Gtk::TextView to Gtk::Grid

Bill Greene via gtkmm-list <[email protected]> Thu, 6 Oct 2022 06:32:29 -0400
Newsgroups gmane.comp.gnome.gtkmm
Message-ID <CABUrC_YVfxJDrzbT05cq+Up=XdJ6FUFhhXm7ejopYbCJ-J5AkQ@mail.gmail.com>
--===============1099431437309527047==
Content-Type: multipart/alternative; boundary="000000000000f5dce305ea5b37a3"

--000000000000f5dce305ea5b37a3
Content-Type: text/plain; charset="UTF-8"

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 <[email protected]>
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();
> >
> >
>

--000000000000f5dce305ea5b37a3
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Thanks for taking=C2=A0a look at this.<div><br></div><div>=
Unfortunately, even after=C2=A0I make the TextView=C2=A0 =C2=A0a class memb=
er, I still don&#39;t see the text displayed in the=C2=A0window.</div><div>=
A concise description=C2=A0of the problem is this:=C2=A0</div><div>If I mak=
e the TextView a child of the window, the text is displayed. If I make the =
TextView a child of a Grid, and the</div><div>Grid a child of the window, t=
he text is not displayed.</div><div><br></div><div>I am assuming there migh=
t be some property of the Grid I need to set?</div></div><br><div class=3D"=
gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, Oct 5, 2022 at 1=
2:40 PM Kjell Ahlstedt &lt;<a href=3D"mailto:[email protected]">kjell=
[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);=
padding-left:1ex">You have declared the TextView=C2=A0 as a local variable =
in the constructor. <br>
It will be deleted when the constructor finishes. You must either <br>
declared it in your window class, like the buttons in<br>
<br>
<a href=3D"https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/blob/master=
/examples/book/grid/examplewindow.h" rel=3D"noreferrer" target=3D"_blank">h=
ttps://gitlab.gnome.org/GNOME/gtkmm-documentation/-/blob/master/examples/bo=
ok/grid/examplewindow.h</a><br>
<br>
or create it with Gtk::make_managed() in the constructor, like the button i=
n<br>
<br>
<a href=3D"https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/blob/master=
/examples/book/scrolledwindow/examplewindow.cc" rel=3D"noreferrer" target=
=3D"_blank">https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/blob/maste=
r/examples/book/scrolledwindow/examplewindow.cc</a><br>
<br>
Den 2022-10-05 kl. 17:00, skrev Bill Greene via gtkmm-list:<br>
&gt; I am trying to add a=C2=A0TextView instance to a Grid. But when I disp=
lay <br>
&gt; the window, it is<br>
&gt; empty. The Grid examples I have seen add buttons to the grid and these=
 <br>
&gt; work fine<br>
&gt; for me. But I don&#39;t understand the difference between adding a but=
ton <br>
&gt; and adding<br>
&gt; a TextView. If anyone can help me with this, I would=C2=A0appreciate i=
t.<br>
&gt;<br>
&gt; Here is my sample code (part of the constructor for my window):<br>
&gt;<br>
&gt; =C2=A0 set_child(m_grid);<br>
&gt; =C2=A0 Gtk::TextView tc;<br>
&gt; =C2=A0 Glib::RefPtr&lt;Gtk::TextBuffer&gt; tb =3D Gtk::TextBuffer::cre=
ate();<br>
&gt; =C2=A0 std::string msg(&quot;cell 1,1&quot;);<br>
&gt; =C2=A0 auto it =3D tb-&gt;insert(tb-&gt;begin(), msg);<br>
&gt; =C2=A0 tc.set_buffer(tb);<br>
&gt; =C2=A0 m_grid.attach(tc, 0, 0);<br>
&gt; =C2=A0 m_grid.set_visible();<br>
&gt;<br>
&gt;<br>
</blockquote></div>

--000000000000f5dce305ea5b37a3--

--===============1099431437309527047==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list

--===============1099431437309527047==--