Re: How to set background/foreground on button, entry, or label?
On Wed, 2004-03-03 at 20:39, Tony Denault wrote: Hi All, After doing some research and hacking, I wrote some code to set the foreground / backgroud color of a button, entry, label. This is still a confusing part of GTK 2.x., an internet search on this question resulted in lots of partial answers, vague description on how it should work, but no clear answer that work across all widgets. Have you seen: http://ometer.com/gtk-colors.html Regards, Owen ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
Re: How to set background/foreground on button, entry, or label?
Tony Denault wrote: On Thu, 4 Mar 2004, Owen Taylor wrote: On Wed, 2004-03-03 at 20:39, Tony Denault wrote: Hi All, After doing some research and hacking, I wrote some code to set the foreground / backgroud color of a button, entry, label. This is still a confusing part of GTK 2.x., an internet search on this question resulted in lots of partial answers, vague description on how it should work, but no clear answer that work across all widgets. Have you seen: http://ometer.com/gtk-colors.html Yes, it was one of the references I came acoss while researching this subject. It indicated using gtk_widget_modify_fg/bg(), but I only got the fg to change for buttonlabel. Could not get the entry text, or background colors for label, entry, button to change. As I stated before, if there is a better technique for gtk 2.0, please modify the code and post. gtk_label directly renders onto the parent (it doesn't have its own window). You can change the text foreground and background colour with pango, but the whole background of the label can be changed by holding it in a gtk_event_box, and changing the fg colour of that (it derives from gtk_widget). Looking in the header file may tell you if a widget has its own window. ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
Re: How to set background/foreground on button, entry, or label?
On Thu, 2004-03-04 at 15:25, Tony Denault wrote: On Thu, 4 Mar 2004, Owen Taylor wrote: On Wed, 2004-03-03 at 20:39, Tony Denault wrote: Hi All, After doing some research and hacking, I wrote some code to set the foreground / backgroud color of a button, entry, label. This is still a confusing part of GTK 2.x., an internet search on this question resulted in lots of partial answers, vague description on how it should work, but no clear answer that work across all widgets. Have you seen: http://ometer.com/gtk-colors.html Yes, it was one of the references I came acoss while researching this subject. It indicated using gtk_widget_modify_fg/bg(), but I only got the fg to change for buttonlabel. Could not get the entry text, or background colors for label, entry, button to change. I suspect both of your issues are covered section of the doc titled Why doesn't setting the color work for me? GtkEntry One possible reason is that the GUI element you want to affect is actually drawn with the text, base, etc. color instead of whatever color you are setting. GtkLabel Yet another possible reason is that some widgets don't have backgrounds; e.g. label widgets. They merely display the background of their parent (i.e. they are transparent). So set the background on their parent; if you want to set the background of a rectangular area around a label, try placing the label in a GtkEventBox widget and setting the background on that. Regards, Owen ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
Re: How to set background/foreground on button, entry, or label?
On Thu, 4 Mar 2004, Owen Taylor wrote: On Wed, 2004-03-03 at 20:39, Tony Denault wrote: Hi All, After doing some research and hacking, I wrote some code to set the foreground / backgroud color of a button, entry, label. This is still a confusing part of GTK 2.x., an internet search on this question resulted in lots of partial answers, vague description on how it should work, but no clear answer that work across all widgets. Have you seen: http://ometer.com/gtk-colors.html Yes, it was one of the references I came acoss while researching this subject. It indicated using gtk_widget_modify_fg/bg(), but I only got the fg to change for buttonlabel. Could not get the entry text, or background colors for label, entry, button to change. As I stated before, if there is a better technique for gtk 2.0, please modify the code and post. Thanks, Tony /---\ | Tony Denault | Email: [EMAIL PROTECTED] | | Institute for Astronomy | Phone: (808) 932-2378 | | 640 North Aohoku Place |Fax: (808) 933-0737 | | Hilo, Hawaii 96720 || \---/ ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
How to set background/foreground on button, entry, or label?
Hi All, After doing some research and hacking, I wrote some code to set the foreground / backgroud color of a button, entry, label. This is still a confusing part of GTK 2.x., an internet search on this question resulted in lots of partial answers, vague description on how it should work, but no clear answer that work across all widgets. I am posting this code to: 1. Provide a working example on how I did it. 2. Maybe the experts can improve on it, or show better methods. 3. Maybe it (or an improved version) can be put in the faq. There are still some problems: 1. The Entry widget's cursor doesn'tt change with the 'Text' color. In my example, the bg color cursor is black = invisible cursor! 2. Different widgets use different properites in the style. I still don't understand the numberous style-fd, bg, light, dark, mid, text, base. 3. Tried using gtk_widget_modify_fg()/gtk_widget_modify_bg(), but never could get them to work on all widgets. So I used MyStyleSetItemColor() - a function from my 1.2x code. code is below my .signature. Tony /---\ | Tony Denault | Email: [EMAIL PROTECTED] | | Institute for Astronomy | Phone: (808) 932-2378 | | 640 North Aohoku Place |Fax: (808) 933-0737 | | Hilo, Hawaii 96720 || \---/ #include gtk/gtk.h void MyStyleSetItemColor( GdkColor color, char item, GtkStyle * style); int main (int argc, char *argv[]) { GtkWidget * base, * table, * entry, * button, * label, * ebox; GtkStyle * style_default, * style_entry_YB, * style_button_YB; GdkColor black = { 0, 0, 0, 0 } , // should use gdk_colormap_alloc_color() yellow = {0, 65535, 65535, 0 }; gtk_init(argc, argv); /* define some styles to apply to my widgets */ style_default = gtk_widget_get_default_style(); /* this style works for entry */ style_entry_YB = gtk_style_copy( style_default ); MyStyleSetItemColor( black, 's', style_entry_YB); // s=base (entry,bg) MyStyleSetItemColor( yellow, 't', style_entry_YB ); // t=Text (entry,fg) /* this style works for buttons */ style_button_YB = gtk_style_copy( style_default ); MyStyleSetItemColor( black, 'b', style_button_YB ); // b=bg (button,bg) MyStyleSetItemColor( yellow, 'f', style_button_YB ); // f=fg (button,fg) base = gtk_window_new( GTK_WINDOW_TOPLEVEL ); table = gtk_table_new( 1, 5, TRUE ); gtk_container_add (GTK_CONTAINER (base), table); /* button - using style_button_YB */ button = gtk_button_new_with_label( button); gtk_widget_set_style(GTK_BIN (button)-child, style_button_YB); gtk_widget_set_style(button, style_button_YB); gtk_table_attach_defaults (GTK_TABLE(table), button, 0, 1, 0, 1); gtk_widget_show(button); /* entry - using style_entry_YB */ entry = gtk_entry_new( ); gtk_entry_set_text( GTK_ENTRY(entry), Entry); gtk_entry_set_width_chars( GTK_ENTRY(entry), 5); gtk_table_attach_defaults (GTK_TABLE(table), entry, 2, 3, 0, 1); gtk_widget_set_style(entry, style_entry_YB); gtk_widget_show(entry); /* label w/ event box for backgroud color */ ebox = gtk_event_box_new(); label = gtk_label_new(label ); gtk_container_add( GTK_CONTAINER(ebox), label ); gtk_widget_set_style( label, style_button_YB); // change label fg color gtk_widget_set_style( ebox, style_button_YB);// bg color provided by ebox gtk_table_attach_defaults (GTK_TABLE(table), ebox, 4, 5, 0, 1); gtk_widget_show(label); gtk_widget_show(ebox); gtk_widget_show(table); gtk_widget_show( base ); gtk_main (); return 0; } /*--- ** MyStyleSetItemColor() - Helper function to change a style. **--- */ void MyStyleSetItemColor( GdkColor color,/* The allocated color to be added to the style */ char item, /* the item to which the color is to be applied */ /* 'f' = foreground; 'b' = background; */ /* 'l' = light; 'd' = dark; */ /* 'm' = mid;'t' = text; */ /* 's' = base. */ GtkStyle * style /* The old style - changes made to a copy */ ) { int i; switch ( item ) { case 'f': case 'F': for ( i = 0; i 5; i++ ) style-fg[i] = color; break; case 'b': case 'B': for ( i = 0; i 5; i++ ) style-bg[i] = color; break; case 'l': case 'L': for ( i = 0; i 5; i++ ) style-light[i] = color; break; case 'd':