Modifying the border color of a GtkEntry
- From: Pierre Wieser <pwieser trychlos org>
- To: gtk-app-devel-list <gtk-app-devel-list gnome org>
- Subject: Modifying the border color of a GtkEntry
- Date: Thu, 22 May 2014 00:38:41 +0200 (CEST)
Hi all,
In the Gtk3 application I am writing, I'd wish show to the user the
erroneous fields by setting the border color of the GtkEntry widgets
to a specific (e.g. red) color.
What I've done:
- allocate a new CSSProvider, loads my .css file and try to apply it:
void
my_utils_entry_set_valid( GtkEntry *entry, gboolean valid )
{
static const gchar *thisfn = "my_utils_entry_set_valid";
static GtkCssProvider *css_provider = NULL;
GError *error;
GtkStyleContext *style;
if( !css_provider ){
css_provider = gtk_css_provider_new();
error = NULL;
if( !gtk_css_provider_load_from_path( css_provider, PKGUIDIR "/ofa.css", &error )){
g_warning( "%s: %s", thisfn, error->message );
g_error_free( error );
g_clear_object( &css_provider );
}
}
if( css_provider ){
style = gtk_widget_get_style_context( GTK_WIDGET( entry ));
if( valid ){
gtk_style_context_remove_class( style, "ofaInvalid" );
gtk_style_context_add_class( style, "ofaValid" );
} else {
gtk_style_context_remove_class( style, "ofaValid" );
gtk_style_context_add_class( style, "ofaInvalid" );
}
gtk_style_context_add_provider( style,
GTK_STYLE_PROVIDER( css_provider ), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION );
}
}
And I wrote a small .css file:
.ofaInvalid {
border-color: red;
color: red;
}
What I see is that only the font color is changed to red, not the border color,
whatever be the state of the widget (active, focus, normal or so).
So the code seems to be correct, but I do not understand why the border color
is not changed ? (because the font color is obviously only useful when the field
is not empty).
So my questions are:
- why my stylesheet doesn't modify the border color of the Gtkentry ?
- how to modify the border color ?
Thanks in advance for your help.
Regards
Pierre
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]