Bring a widget to the foreground
Suppose I designed a custom widget that was made up of two other widgets layered on top of each other. As an example, let's say I wanted a button whose label needed to be at the top of the button, rather than in the centre. I use either a separate label or a graphical image to achieve this. Each time the button gets pressed I need to make sure that it doesn't obscure the other widget. So having done whatever gets done in response to the button press, I need to bring the other widget to the foreground again. Does GTK+ have a method available for achieving this? John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Bring a widget to the foreground
Hi John, On 2 January 2011 13:17, John Emmas wrote: > As an example, let's say I wanted a button whose label needed to be at the > top of the button, rather than in the centre. I use either a separate label > or a graphical image to achieve this. You can just set the alignment on the label to get them to display at the top of the button. > Each time the button gets pressed I need to make sure that it doesn't obscure > the other widget. So having done whatever gets done in response to the > button press, I need to bring the other widget to the foreground again. Does > GTK+ have a method available for achieving this? GTK does not officially support overlapping widgets. However, you can sort-of do it by putting groups of widgets into eventboxes and putting those boxes into a layout. To move to the front, ref the box, remove it from the layout, add again, and unref. It would probably work with other containers too. I hope I've understood what you want. John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Bring a widget to the foreground
On 2 Jan 2011, at 14:40, jcup...@gmail.com wrote: > > You can just set the alignment on the label to get them to display at > the top of the button. > >> [...] > > GTK does not officially support overlapping widgets. However, you can > sort-of do it by putting groups of widgets into eventboxes and putting > those boxes into a layout. To move to the front, ref the box, remove > it from the layout, add again, and unref. It would probably work with > other containers too. I hope I've understood what you want. > Thanks John, To be honest, all I'm trying to do is create a button whose label font can be changed on demand. I've managed to achieve it by using an empty button with a label on top, except that the label doesn't always stay on top! I'm probably being incredibly dim but I couldn't find a way to do this with a standard gtk button. I could change the label's text quite easily but not its font. Am I missing something very obvious? John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Bring a widget to the foreground
On 2 Jan 2011, at 15:39, John Emmas wrote: > > I'm probably being incredibly dim but I couldn't find a way to do this with a > standard gtk button. I could change the label's text quite easily but not > its font. Am I missing something very obvious? > Sorry, that's ambiguous now that I re-read it. What I meant to say was that I can change the _button's_ label text quite easily but not its font. John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Bring a widget to the foreground
- Original Message > From: John Emmas > To: gtk-app-devel-list > Sent: Sun, January 2, 2011 10:42:28 AM > Subject: Re: Bring a widget to the foreground > > > On 2 Jan 2011, at 15:39, John Emmas wrote: > > > > > I'm probably being incredibly dim but I couldn't find a way to do this > > with >a standard gtk button. I could change the label's text quite easily but not >its font. Am I missing something very obvious? > > > > Sorry, that's ambiguous now that I re-read it. What I meant to say was that > I >can change the _button's_ label text quite easily but not its font. > > John > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > I would use gtk_label_set_attributes(), http://library.gnome.org/devel/gtk/stable/GtkLabel.html#gtk-label-set-attributes That would probably do what you want. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Bring a widget to the foreground
On 2 Jan 2011, at 17:19, Lance Dillon wrote: > > I would use gtk_label_set_attributes(), > http://library.gnome.org/devel/gtk/stable/GtkLabel.html#gtk-label-set-attributes > > That would probably do what you want. > I followed that link but it doesn't look as if it would work for a button. I'd need to be able to get the button's label object (if there is one) but I can't see an obvious way of getting it :-( John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Bring a widget to the foreground
Hi. > I followed that link but it doesn't look as if it would work for a button. > I'd need to be able to get the button's label object (if there is one) but I > can't see an obvious way of getting it :-( How you'll get your hands on GtkLabel object inside button depends on how your button has been constructed. The safest and simplest way of doing this would be to manually add label to your button using code like this: /* *** CODE *** button = gtk_button_new (); label = gtk_label_new ("Label"); gtk_container_add (GTK_CONTAINER (button), label); /* *** end CODE *** If this approach is not right for your situation, you'll need to walk the widget hierarchy in the button until you find your label. Hierarchies as produced by different constructors are (I'm almost certainly wrong here, but I'm sure someone will correct me): gtk_button_new_with_label(): button->label gtk_button_new_from_stock(): button->hbox->label `>image Exact widget tree doesn't really matter, since it's relatively easy to create code that recursively checks for GtkLabel. Hope this helps a bit. Tadej -- Tadej Borovšak tadeboro.blogspot.com tadeb...@gmail.com tadej.borov...@gmail.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Bring a widget to the foreground
On 2 January 2011 15:39, John Emmas wrote: > To be honest, all I'm trying to do is create a button whose label font can be > changed on demand. I've managed to achieve it by using an empty button with > a label on top, except that the label doesn't always stay on top! Ah, OK, yes, there's a much simpler technique. Try something like this: txt = "some text to display"; font = "sans 12"; snprintf (button_text, 256, "%s", font, txt); gtk_label_set_markup ( GTK_LABEL (gtk_bin_get_child (GTK_BIN (button))), button_text); Assuming 'button' is a regular gtk button containing a label. John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Bring a widget to the foreground
Many thanks John, I'll try your suggestion tomorrow. Thanks also, Tadej. That's pretty much how I created the button at my first attempt. It created the button OK but I couldn't find a way to change the font later. :-( John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list