Re: Set the background color in GTK1
- From: M Santhoff t-online de (Marc Santhoff)
- To: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: Set the background color in GTK1
- Date: Mon, 19 Apr 2004 14:25:20 +0200
Am Mo, den 12.04.2004 schrieb Kevin DeKorte um 22:42:
Peter,
I'm not, but hi Kevin!
Didn't seem to do it
I do this to get the style
style = gtk_style_copy(gtk_widget_get_style(gtkwidget));
color.red = style->bg[GTK_STATE_NORMAL].red;
color.green = style->bg[GTK_STATE_NORMAL].green;
color.blue = style->bg[GTK_STATE_NORMAL].blue;
black.red = 0;
black.green = 0;
black.blue = 0;
This to set the color
style->bg[GTK_STATE_NORMAL].red = black.red;
style->bg[GTK_STATE_NORMAL].green = black.green;
style->bg[GTK_STATE_NORMAL].blue = black.blue;
gtk_widget_set_style(gtkwidget,style);
gtk_widget_ensure_style(gtkwidget);
And this to restore it
style->bg[GTK_STATE_NORMAL].red = color.red;
style->bg[GTK_STATE_NORMAL].green = color.green;
style->bg[GTK_STATE_NORMAL].blue = color.blue;
gtk_widget_set_style(gtkwidget,style);
gtk_widget_ensure_style(gtkwidget);
And the background color always stays the default grey.
There's a tutorial by Havoc Pennington on this topic, but I lost the URL
(could be: http://pobox.com/~hp ), so I post a short part for GTK+ 1.2:
Short answer: how to set the color of a widget
In GTK+ 1.2:
GtkRcStyle *rc_style;
GdkColor color;
/* There are two good ways to fill in a color */
/* 1) Initialize r/g/b components, they are 16-bit values */
color.red = 65535;
color.green = 0;
color.blue = 0;
/* 2) Parse a color string; an HTML color spec such as "#FF0000"
* is allowed here too
*/
gdk_color_parse ("red", &color);
/* After filling in your GdkColor, create a GtkRcStyle */
rc_style = gtk_rc_style_new ();
/* Set foreground (fg) color in normal state to red */
rc_style->fg[GTK_STATE_NORMAL] = color;
/* Indicate which colors the GtkRcStyle will affect;
* unflagged colors will follow the theme
*/
rc_style->color_flags[GTK_STATE_NORMAL] |= GTK_RC_FG;
gtk_widget_modify_style (widget, rc_style);
gtk_rc_style_unref (rc_style);
As you can see, I think you should use "gtk_widget_modify_style()" and
check the definition of the used types.
I had some trouble with this myself.
HTH,
Marc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]