> 2008/3/19, LIU Chun Hung <[EMAIL PROTECTED]>: >> Hi, >> >> I want to create three buttons with different colors. But three buttons >> are with the same colors at the final. What's wrong? Anybody help? My >> program code is as below: > [snip] >> bn1_style = gtk_widget_get_style(bn1); >> bn1_style->bg[GTK_STATE_NORMAL] = red_color; >> gtk_widget_set_style(bn1, bn1_style); >> bn2_style = gtk_widget_get_style(bn2); >> bn2_style->bg[GTK_STATE_NORMAL] = green_color; >> gtk_widget_set_style(bn2, bn2_style); >> bn3_style = gtk_widget_get_style(bn3); >> bn3_style->bg[GTK_STATE_NORMAL] = blue_color; >> gtk_widget_set_style(bn3, bn3_style); >> >> Three buttons are in blue at the final. > > That's because gtk_widget_get_style() returns the active style object > for a widget, which very likely is exactly the same object for all > button widgets. > > So first of all, NEVER TOUCH THE STYLE OBJECTS MEMBERS DIRECTLY. This > is not going to be even possible for much longer, and it is generally > very bad (though very often used) practise to change an objects > members directly. In this case it ends up modifying the property for > all widgets that share the style object. > > To make it work as intended you can use the gtk_widget_modify_*() > functions to change the appearance of a widget. But note that this too > is considered bad practise unless you have a very specific needs > and/or control all aspects of the appearance (in order to not have > black text on black background for example) regardless of any > user-selected GTK+ theme. > In fact, I have already try gtk_widget_modify_*() functions to change the color of the widget, but it does not work. The widget is still in the default color. So what is the right way to change widget's appearance?
Regards, Hung > -- > Kalle Vahlman, [EMAIL PROTECTED] > Powered by http://movial.fi > Interesting stuff at http://syslog.movial.fi > _______________________________________________ maemo-developers mailing list [email protected] https://lists.maemo.org/mailman/listinfo/maemo-developers
