[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gtk-app-devel
Subject:    Modifying the border color of a GtkEntry
From:       Pierre Wieser <pwieser () trychlos ! org>
Date:       2014-05-21 22:38:41
Message-ID: 357451400.5133.1400711921750.JavaMail.zimbra () wieser ! fr
[Download RAW message or body]

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
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic