Re: changing button colours



bill -- here's what i do to set the color of a button...which means it's
probably not the best way, but anyway...

you don't need to allocation the color -- 'cause applying the style does
it for you...  is this different than what you wanted?

	GtkStyle* my_style;
	GtkWidget* button = gtk_button_new();
	GdkColor myGdkColor = {0, 0xAFFF, 0xFFFF, 0xCFFF};
	
	my_style = gtk_style_copy( gtk_widget_get_default_style() );
	
	my_style->bg[GTK_STATE_NORMAL] = myGdkColor;
	my_style->bg[GTK_STATE_ACTIVE] = myGdkColor;
	my_style->bg[GTK_STATE_PRELIGHT] = myGdkColor;
	my_style->bg[GTK_STATE_SELECTED] = myGdkColor;
	my_style->bg[GTK_STATE_INSENSITIVE] = myGdkColor;

	gtk_widget_set_style(button, mt_style);	






Donovan Artz
505 665 4072
NIS-9, AI SuperGuy
Los Alamos National Laboratory

> 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?
> At present I simply overwrite the widget->style->bg_gc[] entry
> and this works fine until I close things down when I get a
> segmentaion violation in gtk_gc_key_hash (from gtk_gc_release),
> so I assumed that I needed to take into account the reference
> counts. I changed my code as follows:
> 
> 	gdk_gc_unref(widget->style->bg_gc[0]);
> 	gdk_gc_ref(mygc);
> 	widget->style->bg_gc[0] = mygc;
> 
> My reasoning was that the old gc was no longer needed here,
> so it could be unreffed, and the new one had its count bumped.
> 
> This was worse than ever - the program segfaults immediately on
> starting up, in XSetClipRectangle. Am I doing something absolutely
> stupid here? I've tried scanning the FAQ, the Tutorials and the
> source code and haven't (as yet) found any clue as to what I
> ought to be doing.
> 
> Many thanks in advance,
> 
> Bill
> 
> -- 
> +-----------------------------------------------+
> | Bill Purvis, Musical Engineer                 |
> | 35 Chapel Road, Penketh, Warrington, Cheshire |
> | WA5 2NG. phone: 01 925 725731                 |
> | e-mail: bill p bigfoot com                    |
> | www: http://bil.members.beeb.net              |
> +-----------------------------------------------+
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
> 





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