Re: how to set colors



How can I change the bg and fg color of a given widget?
 For example I want a screen blu bg and white fg, and within that screen
 a Clist widget red bg and yellow fg.
 If I set the style of Clist , the whole screen bg and fg colors change.
 Where can I find a complete documentation about GTK and GDK function and
 widgets

Have a look at these examples, with a button and a label
(you can set the foreground but not the background color 
with a label because it has no X window), they should work ;-)
Carlos

---------------------------------------
GtkWidget *button;
GtkWidget *label;
GdkColor color;
GtkStyle *style;

/* yellow background using button and short (16 bit) r,g,b colors */

color.pixel = 0;
color.red = 65535;
color.green = 65535;
color.blue = 0;

style = gtk_style_copy (gtk_widget_get_style (button));
style->bg[GTK_STATE_NORMAL] = color;
style->bg[GTK_STATE_ACTIVE] = color;
style->bg[GTK_STATE_PRELIGHT] = color;
style->bg[GTK_STATE_SELECTED] = color;
style->bg[GTK_STATE_INSENSITIVE] = color;
gtk_widget_set_style (button, style);

gtk_style_unref (style);

/* red foreground using label and color string */

gdk_color_parse ("red", &color);

style = gtk_style_copy (gtk_widget_get_style (label));
style->fg[GTK_STATE_NORMAL] = color;
style->fg[GTK_STATE_ACTIVE] = color;
style->fg[GTK_STATE_PRELIGHT] = color;
style->fg[GTK_STATE_SELECTED] = color;
style->fg[GTK_STATE_INSENSITIVE] = color;
gtk_widget_set_style (label, style);

gtk_style_unref (style);
----------------------------------




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