Re: Change colour of an entry



On Wed, 3 Mar 2004, Johnny wrote:
Style->color_flags[GTK_STATE_NORMAL] =
(GtkRcFlags)(Style->color_flags[GTK_STATE_NORMAL] | GTK_RC_FG);

and

Style->color_flags[GTK_STATE_NORMAL] =
(GtkRcFlags)(Style->color_flags[GTK_STATE_NORMAL] | GTK_RC_BASE);

to activate the color changes.

I've tried it but I can't see the foreground color and the base color of the
entry at the same time, I see only the color that I change first.
Hello Johnny,
here is a working example:

int main(
  int argc,
  char **argv)
{
  GdkColor colYellow, colBlue;
  GtkRcStyle *style;

  /* initialize the application */
  gtk_init(&argc, &argv);

  /* create widgets */
  GtkWidget *pMainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  GtkWidget *pEntry = gtk_entry_new();
  gtk_container_add(GTK_CONTAINER(pMainWindow), pEntry);

  /* initialize colors */
  gdk_color_parse("yellow", &colYellow);
  gdk_color_parse("blue", &colBlue);

  /* modify text color (your 1st function) */
  style = gtk_widget_get_modifier_style(pEntry);
  style->text[GTK_STATE_NORMAL] = colYellow;
  style->color_flags[GTK_STATE_NORMAL] =
    (GtkRcFlags)(style->color_flags[GTK_STATE_NORMAL] | GTK_RC_TEXT);
  gtk_widget_modify_style(pEntry, style);

  /* modify base color (your 2nd function) */
  style = gtk_widget_get_modifier_style(pEntry);
  style->base[GTK_STATE_NORMAL] = colBlue;
  style->color_flags[GTK_STATE_NORMAL] =
    (GtkRcFlags)(style->color_flags[GTK_STATE_NORMAL] | GTK_RC_BASE);
  gtk_widget_modify_style(pEntry, style);

  /* show widgets and start runtime loop */
  gtk_widget_show_all(pMainWindow);
  gtk_main();

  return 0;
}

Note that to change the color of the text you have to use style->text,
and not style->fg.

Regards,
                     Peter
-- 
====================================================================
Peter Krüger

applied software solutions (appss) GmbH
Sandtorstr. 23
D-39106 Magdeburg
Germany

Phone:  +49-(0)391-54486-19388
Fax:    +49-(0)391-54486-19222
email:  krueger appss de
URL:    http://www.appss.de

Managing Director: Uwe Hess, Dietmar Schäfer
Register: HRB12386, AG Mageburg

"Virtual business becomes reality!"

This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail. Any
unauthorised copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
====================================================================




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