Re: Font changes

On Sun, Dec 14, 2003 at 08:15:24PM -0800, Sheldon Simms wrote:
Hi all,

I'm new to GTK+ programming and I'd like to know if it
is possible to change the font used by standard
widgets such as GtkEntry.

My particular desire at the moment is for
GtkSpinButton to use a monospaced font, but I wouldn't
mind knowing if it is generically possible to set a
font, regardless of theme, etc., for individual

Sometimes, its best to use the themeing or, more precisely, rcstyle
system for this purpose. First, make sure that you name all your
customizable widgets with gtk_widget_set_name or setting the name
property. Then you call gtk_rc_parse or gtk_rc_add_default_files
for any number of RC customization files with documented path
locations. You might parse a site wide one, and then a user
provided (located in the home directory). You can ship a default file
along with your application that sets things to reasonable defaults. The
advantage of this method is that you give the user full customizability
without having to recompile.
The disadvantage is that you have to maintain another data file.

You can override the RcStyle settings completely with
gtk_widget_set_style, or you can override certain settings with the
gtk_widget_modify_* functions. For example, to ensure a monospace font,
you would create a PangoFontDescription, and call
pango_font_description_set_family(fd, 'monospace'). Then simply pass this
FontDescription to the widget with gtk_widget_modify_font. Of course, it
will be impossible to override this setting from an RC file. 


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