Re: changing button colours



Bill Purvis <bill p bigfoot com> writes:
> Hi, I have been programming gtk+ for a while now, but I'm having
> problems changing the background colour of widgets - specifically
> buttons, but that's probably not relevant. I need to be able to
> change the colours when the buttons have been pressed. Is there
> a recommended way of doing this?

The correct way is:

 - create a GtkRcStyle
 - set the background color in the RcStyle, and set the flag in 
   the RcStyle indicating that the background color is set
 - call gtk_widget_modify_style() to override the widget's current
   style with your RcStyle
 - unref the RcStyle, the widget will have kept a reference to it

This method allows your changes to survive theme switches. If you just
modify the GtkStyle instead of adding the GtkRcStyle, changing themes
will make your modification go away.

The GTK 2.0 sources have a function gtk_widget_modify_bg() that does
this for you.

Havoc




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