Re: Changing background colors



John Cupitt wrote:

> You should be able to change the whole application with just your
gtkrc. Try this in your ~/.gtkrc-2.0 file and (almost) everything should
go a very ugly pink:
> 
> style "pink"
> {
>   bg[NORMAL]      = { 1.000, 0.80, 0.80 }
>   fg[NORMAL]      = { 1.000, 0.40, 0.60 }
>   bg[PRELIGHT]    = { 1.000, 0.80, 1.00 }
>   fg[PRELIGHT]    = { 1.000, 0.40, 0.60 }
>   bg[ACTIVE]      = { 1.000, 0.80, 0.80 }
>   fg[ACTIVE]      = { 1.000, 0.40, 0.60 }
>   bg[SELECTED]    = { 1.000, 0.60, 0.80 }
>   fg[SELECTED]    = { 1.000, 0.00, 0.00 }
>   base[SELECTED]  = { 1.000, 0.60, 0.80 }
>   text[SELECTED]  = { 1.000, 0.00, 0.00 }
>   base[ACTIVE]    = { 1.000, 0.80, 0.80 }
>   text[ACTIVE]    = { 1.000, 0.00, 0.00 }
> }
> 
> class "GtkWidget" style "pink"
Just tried it: I can't change "background" (the white area) of entries,
combo boxes, treeviews, etc...

Is there a way to change them?


Hi Diego:

I've solved that problem of yours bye using the widget GtkStyle but the
only problem is the if you want to change the background color of
several widgets (buttons, entries, textareas,etc)  you will have to do
it one by one, that's why is better to do it using rc files. But you
know, i can't use rc files also! 

Here is a code showing the way i do it, it has some comments in spanish
because i am form El Salvador and i don't want to change it, i'm kind of
tired, I hope it help you: 

#include <gtk/gtk.h>
#include <gdk/gdk.h>

GtkWidget	*ventana;
GtkStyle	*mi_estilo;
GdkColor 	color_texto, color_fondo;

void Cambio_Color(void);

int main(int argc, char* argv[])
{
  GtkWidget	*etiqueta,
  		*texto,
  		*vbox;



  gtk_init(&argc, &argv);

  color_fondo.red=0;			color_texto.red=0xffff;
  color_fondo.green=0;			color_texto.green=0;
  color_fondo.blue=0;			color_texto.blue=0xffff;



  //texto=GTK_WIDGET(gtk_text_new(NULL, NULL));
  //gtk_widget_set_usize(GTK_WIDGET(texto),50,25);
  //gtk_signal_connect(GTK_OBJECT(texto),"button-press-event",
GTK_SIGNAL_FUNC(Cambio_Color), NULL);


   //vbox=gtk_vbox_new(TRUE,5);
   //gtk_box_pack_end_defaults(GTK_BOX(vbox),texto);
   //gtk_container_set_border_width(GTK_CONTAINER(vbox),10);

  //Cada widget tiene su estilo....por defecto esta definido segun el
theme que tenga KDE en ese momento.
  //Ahora creamos nuestro estilo.
  mi_estilo= gtk_style_new ();


  ventana=gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
gtk_window_set_position(GTK_WINDOW(ventana),GTK_WIN_POS_CENTER_ALWAYS);
  //gtk_container_add(GTK_CONTAINER(ventana),vbox);
  gtk_signal_connect(GTK_OBJECT(ventana),"destroy",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
  gtk_signal_connect(GTK_OBJECT(ventana),"key-press-event",
GTK_SIGNAL_FUNC(Cambio_Color),NULL);


  //La siguiente directiva maneja el color de fondo para cualquier
widget que tenga fondo e.j GtkWindows o GtkButtons
  //Recordar que widget como containers, labels no tienen fondo o como
dicen en los expertos tienen fondo trasparente por eso toman
  //el fondo de su widget contenerdor.
  mi_estilo->bg[GTK_STATE_NORMAL]=color_fondo;
  mi_estilo->text[GTK_STATE_NORMAL]=color_texto;			//Maneja el color del
texto

  //Maneja el color base de algunos widgets...en lo particular me he
dado cuenta que cambia el color de fondo pero widgets como
  //Gtkentrys o Gtktext.
  //mi_estilo->base[GTK_STATE_NORMAL] =color_fondo;

  //Cargamos nuestro estilo a la widget que queramos
  gtk_widget_set_style (GTK_WIDGET (ventana), mi_estilo);

  gtk_widget_show_all(ventana);

  /*
  *  Nota final.
  *  La estructura style tiene muchos variables miembros mas que pueden
ser variadas. Vea a API encontrara
  *  varias mas. Hay una muy interesente que es una GTkPixmap que segun
he leido posibilita colocar una imagen de fondo
  *  a un widget!...Mi idea es colocar una imagen de fondo de la Ti-89 a
una calculadora que yo he hecho...creo que se veria ok, no?
  *
  */


  gtk_main();
  return 0;
}







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