Re: why i can't set background of widget?



gxw wrote:

After run the following simple code,the button background is black,and can't see "Hello World",who can tell 
me the reason?

   style=gtk_style_new();
   style->bg[GTK_STATE_NORMAL].red=0;
   style->bg[GTK_STATE_NORMAL].green=0;
   style->bg[GTK_STATE_NORMAL].blue=255;
   gtk_widget_set_style(button,style);  
You just specifying r/g/b components of the color, try allocate color before (this will set the pixel value). Better solution is to use gtk_widget_modify_bg() function:
http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#gtk-widget-modify-bg
You can pass non-allocated color as parameter.

As for color allocation, look at:
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Colormaps-and-Colors.html

   Olexiy




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