Re: Bring a widget to the foreground
- From: John Emmas <johne53 tiscali co uk>
- To: gtk-app-devel-list <gtk-app-devel-list gnome org>
- Subject: Re: Bring a widget to the foreground
- Date: Fri, 7 Jan 2011 11:33:43 +0000
On 2 Jan 2011, at 21:00, jcupitt gmail com wrote:
On 2 January 2011 15:39, John Emmas <johne53 tiscali co uk> 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,
"<span font_desc=\"%s\" size=\"medium\">%s</span>",
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.
Thanks for the suggestion John. I needed to modify your code slightly because strictly speaking, I'm using
gtkmm rather than gtk+ but the basic technique worked. In fact, once I realised that I could obtain a
pointer to the button's label object, I found that I could simply call Gtk::Label_modify_font() to modify the
font too (assuming I had a suitable Pango::FontDescription object). The best thing though is that I managed
to get rid of my clumsy composite widget, so I now have a button whose font can be changed on demand PLUS the
button's label is always visible, exactly as it's supposed to be! So success all round, I'd say! However,
there's a minor problem with both strategies....
Although I can now change the button's label font, the new font seems to be quite transitory and certain
operations seem to reset it. For example if (later) I change the label's text (e.g. if it currently says
"This message" and I change it to say "That message") the font will immediately revert back to whatever it
was when the button got created. I could get around this by maintaining a persistent object somewhere that
described the last font that I set but it would be neater and more intelligent if I could "get" the label's
current font (immediately prior to changing its text) and then "set" it back to what it should be.
And therein lies the problem.... I can't see any obvious method of retrieving a widget's current font.
gtk_widget_modify_font() allows me to set a new font but it doesn't return anything that would describe the
widget's previous font. Nor does there seem to be any other way of retrieving a widget's current font
AFAICT. Am I missing something obvious?
John
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]