Re: [gtk-list] Changing the font





> Is there any documentation on changing the font in widgets such as the
> clist widget?  It looks like this is tied into the style object, but
> there seems to be no documentation about that, either.

Ok, I asked about this stuff a while ago, and nobody had a good answer, 
and the docs aren't there yet, but I finally figured it out.  Maybe I'll 
see if they'll let me write up some docs for GtkStyle, although I can't 
say I've figured out that much of it either.

I haven't used the clist widget, so I'm not familiar with the items that 
go in it, but logic would stand that they are derived from GtkWidget, and 
the style object works with any widget.

First you need to aquire the current style for the widget you change.

GtkStyle *s = gkt_style_copy(gtk_widget_get_style(WidgetInQuestion));
gtk_style_ref(s);

Now you can change things which are members of the GtkStyle structure :

Font:
  s->font = gdk_font_load("X-Font-String-chock-full-o-dashes-goes-in-here");

ForeGround Color :

GdkColor *f = (GdkColor*) malloc(sizeof(GdkColor));
f->red = 25*(65535/255);
f->green ...
f->blue ...
s->fg[GTK_STATE_NORMAL] = *f;

Same thing for background color.  Allocate a GdkColor structure, set
the values, and then put it int the bg[GTK_STATE_NORMAL] member.
Theres more about this in the Gtk FAQ.  I think you need to call some
actual color allocation routines if you need a bunch of colors, but I'd
figure for fore/back colors it's probably not a big deal.

Also, remember some widgets are transparent, so if you want to set the
background color, you actually have set the background color of the 
parent.  The reverse can also happen.  To set the foreground of a button,
you have to acquire a pointer to the widget contained in it.

> Also, I'm surprised to see that the font selection dialog fron the gimp
> isn't found in gtk. Could this be done in the future?

Definitely.  It might be nice to be able to load fonts without having to
figure out an XLFD string or whatever it's called.  A new user would never
want to deal with those things.

Later,
Ben Boule



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]