Re: changing a widget's color at runtime



Patrick Schweiger wrote:
> Paul Barton-Davis wrote:
> >  please don't do this. Use
> >
> >           status_lbl1->set_name ("StatusLabel");
> >           status_lbl2->set_name ("StatusLabel");
> >
> > and then load a GTK RC file with:
> >
> >     style "status_label" {
> >         fg[NORMAL] = { 0.93, 0.94, 0.23 }
> >     }
> >     widget "*StatusLabel" style "status_label"
> 
> I've read similar advice (might have been yours for all I know) in previous
> messages on this list. I am using a massive GTK rc to set color preferences
> for components with "static" color. The reason I resorted to this ugly code
> is because I want to change the color at run time ... 
> the only way I see to accomplish something like this
> would be to create 12 labels, set_naming() each set of two, then hiding the
> set that's currently visible, and showing the set that reflects the
> application's new state ... this can certainly be done ... but I would
> argue that this paradigm isn't much prettier (if at all).
> 
> If you find there is a "cleaner" way to accomplish something like this
> using RC files I would love to hear from you again - maybe I'm just not
> seeing the light ;)

Paul is right, you're better off with .gtkrc files. The trick is that
you can set_name() at any time, changing the name updates the style, and
it's a cheap call. In my app I have:

style "error_style" {
	bg[]..
}
style "clean_style" {
	bg[]..
}
style "leaf_style" {
	bg[]..
}
etc.
widget "*error_widget" style "error_style"
widget "*clean_widget" etc.

Then when one of my widgets changes state, I set_name() to the new state
... and it is automcatically updated with the new style.

HTH,

John
--
John Cupitt, john cupitt ng-london org uk, +44 (0)20 7747 2570
VASARI Lab, The National Gallery, Trafalgar Square, London, WC2N 5DN




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