Re: [gtk-list] Changing widget attributes in gtk



Ben R. Boule wrote:
> I've been reading through the tutorials,reference docs, etc.. and I can't 
> figure out how to do stuff like change colors and fonts and stuff like that.
> 
> Right now I'm trying to figure out how to change the 
> background/foreground color of a label, and also change the font for the 
> label.  Do I need to use gdk to do this?

I don't know how to change a widget's color as I've never
had occasion to try, but changing fonts is easy.  Basically,
you make a copy of the widget's style and then change that
copy.  I suspect changing colors is awfully similar.  You
need to do this because every new widget inherits (points
to) the same style.

  GtkWidget    *widget;
  GtkStyle     *style;

  ...    /* make widget */

  style = gtk_style_copy( gtk_widget_get_style( widget ) );
  gtk_widget_set_style( widget, style );
  style->font = 
    gdk_font_load("-adobe-symbol-medium-r-normal-*-*-120-*-*-p-*-adobe-*");

  ...    /* etc. and show widget */

Change "-adobe-symbol-yadda-yadda-yadda" to whatever font
you want.  (x)fontsel is great for this.



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