Re: Add Gtk::TextView to Gtk::Grid
Bill Greene via gtkmm-list <[email protected]> Thu, 6 Oct 2022 09:51:14 -0400
| Newsgroups | gmane.comp.gnome.gtkmm |
|---|---|
| Message-ID | <CABUrC_b=8jwX=wz2_6WUrQKTickbZ0OjpFZLPGmG25XvEhNqww@mail.gmail.com> |
--===============2878803940070677583== Content-Type: multipart/alternative; boundary="000000000000c1f8a905ea5dfeed" --000000000000c1f8a905ea5dfeed Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 <[email protected]> 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 =C3=A0s 07:33, Bill Greene via gtkmm-list < > [email protected]> 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 <[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/exampl= es/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/exampl= es/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 thes= e >>> > 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 =3D Gtk::TextBuffer::create(); >>> > std::string msg("cell 1,1"); >>> > auto it =3D tb->insert(tb->begin(), msg); >>> > tc.set_buffer(tb); >>> > m_grid.attach(tc, 0, 0); >>> > m_grid.set_visible(); >>> > >>> >> >> --000000000000c1f8a905ea5dfeed Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Many thanks! It seems that the following call was the key = to my problem:<div>m_TextView.set_expand();<br></div><div>This call seems v= ery non-intuitive to me; I would have expected the TextView to automaticall= y expand</div><div>based on the contents of the TextBuffer.</div><div><br><= /div><div>Or, to ask the question another way: Why does the TextView displa= y correctly when it is added as a=C2=A0</div><div>child of the window but n= ot when it is placed in a Grid?</div><div><br></div><div><br></div></div><b= r><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, = Oct 6, 2022 at 9:42 AM Kjell Ahlstedt <<a href=3D"mailto:kjellahlstedt@g= mail.com">[email protected]</a>> wrote:<br></div><blockquote class= =3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg= b(204,204,204);padding-left:1ex"> =20 =20 =20 <div> <p>set_child(m_grid); shows that this is gtkmm4.</p> <p>I made some tests with the TextView example in gtkmm-documentation,</p> <p><a href=3D"https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/tree= /master/examples/book/textview" target=3D"_blank">https://gitlab.gnome.org/= GNOME/gtkmm-documentation/-/tree/master/examples/book/textview</a></p> <p>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.<br> The text in the TextView was shown.</p> <p>2. Removed the ScrolledWindow.<br> The TextView was not shown. Or, rather, it was minimized.</p> <p>3. Added m_TextView.set_expand();<br> The TextView was shown again.<br> </p> <div>Den 2022-10-06 kl. 13:00, skrev Rodolfo Ribeiro Gomes:<br> </div> <blockquote type=3D"cite"> =20 <div dir=3D"ltr"> <div>If you are gtkmm3, widgets are hidden by default.</div> <div>You should call Gtk::Container::show_all_children() or Gtk::Widget::show_all().</div> <div><br> </div> <div>AFAIK, in gtkmm4 this isn't necessary anymore, as widgets are (finally) visible by default.<br> </div> </div> <br> <div class=3D"gmail_quote"> <div dir=3D"ltr" class=3D"gmail_attr">Em qui., 6 de out. de 2022 = =C3=A0s 07:33, Bill Greene via gtkmm-list <<a href=3D"mailto:gtkmm-lis= [email protected]" target=3D"_blank">[email protected]</a>> escreveu:<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"> <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 member, I still don'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 make 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, the text is not displayed.</di= v> <div><br> </div> <div>I am assuming there might 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 12:40 PM Kjell Ahlstedt <<a href=3D"mailto:kjellahlstedt@g= mail.com" target=3D"_blank">[email protected]</a>> 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 decl= ared 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" targe= t=3D"_blank">https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/blob/mast= er/examples/book/grid/examplewindow.h</a><br> <br> or create it with Gtk::make_managed() in the constructor, like the button in<br> <br> <a href=3D"https://gitlab.gnome.org/GNOME/gtkmm-documentation= /-/blob/master/examples/book/scrolledwindow/examplewindow.cc" rel=3D"norefe= rrer" target=3D"_blank">https://gitlab.gnome.org/GNOME/gtkmm-documentation/= -/blob/master/examples/book/scrolledwindow/examplewindow.cc</a><br> <br> Den 2022-10-05 kl. 17:00, skrev Bill Greene via gtkmm-list:<br> > I am trying to add a=C2=A0TextView instance to a Grid. B= ut when I display <br> > the window, it is<br> > empty. The Grid examples I have seen add buttons to the grid and these <br> > work fine<br> > for me. But I don't understand the difference betwee= n adding a button <br> > and adding<br> > a TextView. If anyone can help me with this, I would=C2=A0appreciate it.<br> ><br> > Here is my sample code (part of the constructor for my window):<br> ><br> > =C2=A0 set_child(m_grid);<br> > =C2=A0 Gtk::TextView tc;<br> > =C2=A0 Glib::RefPtr<Gtk::TextBuffer> tb =3D Gtk::TextBuffer::create();<br> > =C2=A0 std::string msg("cell 1,1");<br> > =C2=A0 auto it =3D tb->insert(tb->begin(), msg);<b= r> > =C2=A0 tc.set_buffer(tb);<br> > =C2=A0 m_grid.attach(tc, 0, 0);<br> > =C2=A0 m_grid.set_visible();<br> ><br> </blockquote> </div> <br> </blockquote> </div> </blockquote> </div> </blockquote></div> --000000000000c1f8a905ea5dfeed-- --===============2878803940070677583== 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 --===============2878803940070677583==--