Re: Cannot set foreground colour of Entry widget



Try this code. I use this in gtk+-1.2 and work well. colore1 is the text color and colore2 the background color, I set also the font of the text, the widget is the entry:

you can call in this way:
color_set_display(GTK_WIDGET(entry), "pale green", "black");

void color_set_display(GtkWidget *widget, gchar *colore1, gchar *colore2)
{
GtkStyle    *style;

GdkColormap *cmap;
GdkColor    color;
GdkFont     *font;


    style=gtk_style_new();

    font=gdk_font_load("-schumacher-clean-bold-r-normal-*-14-*-*-*-*-*-iso646.1991-*");

    if (font != NULL) style->font=font;

    cmap = gdk_colormap_get_system();
    gdk_color_parse(colore1, &color);

    if(!gdk_colormap_alloc_color(cmap, &color, TRUE, TRUE))
    {
    g_error("couldn't allocate colour");
    }

    style->fg[GTK_STATE_NORMAL]=color;

    gdk_color_parse(colore2, &color);

   if(!gdk_colormap_alloc_color(cmap, &color, TRUE, TRUE))
    {
    g_error("couldn't allocate colour");
    }

    style->base[widget->state]=color;

    gtk_widget_set_style(widget, style);

}


Date: Wed, 23 Jul 2003 16:16:18 +0200
From: Preben Randhol <randhol+gtk pvv org>
To: Gtk-List <gtk-list gnome org>
Subject: Cannot set foreground colour of Entry widget
Organization: PVV

I have problems setting the foreground colour of an Entry widget. In
Gtk+-1.2 I modified a Style and then applied this to get say red colour
on the text of the Entry widget text. This way still works for Label
(though I use pango's markup instead now). However for a Entry widget
this approach does not work anymore. Is there something special one need
to do in Gtk+-2.x for Entry widgets?

I want to change colour if the string that is entered is not correct.

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php


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