Previously, I would adjust the background colors of widgets using
gtk_widget_override_background_color
. However, this function is no longer supported, so I am looking to migrate to utilizing GtkCssProvider
.
I have discovered that I can modify the background color of an entry field with code like this:
GtkCssProvider *provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
".entry { background: #927373}", -1, NULL);
gtk_style_context_add_provider (gtk_widget_get_style_context (entry_field),
GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
This solution works well. Yet, I still need the ability to revert the background color back to its default state under specific conditions. I attempted using:
provider = gtk_css_provider_get_default ();
gtk_style_context_add_provider (gtk_widget_get_style_context (entry_field),
GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
Unfortunately, this has no effect. Additionally, trying:
gtk_css_provider_load_from_data (provider,
".entry { background: #none}", -1, NULL);
is not ideal because it changes the widget's default background color (which could be white or another color depending on the theme) to grey after setting it as #none.
Is there a way for me to reset the background color to its default value without relying on deprecated functions?