GtkCssProvider *cssProvider = gtk_css_provider_new();
GError *error = NULL;
gtk_css_provider_load_from_resource(cssProvider, "/css/style.css");
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_USER);
if (error)
{
// Display a warning if the stylesheet is not loaded
g_warning("%s", error->message);
// Free the memory allocated for the error
// and acknowledge the error has been processed
g_clear_error(&error);
}
And change the name of the GtkButton to apply the syle based on the context.
Everything works great!
Now I have to to run my app on a Linux Debian Bullseye 11, Linux Kernel 5.4.142 SOM IMX8 CPU, with Wayland and Weston compositor; i installed the gtk3-dev package and just changed the include from “x86_64” to “aarch64”. The app run, everything seems to works except that the “background-color” properties in the CSS file that is not applied: the buttons are round ( border-radius: 50px; so the css file is loaded and applied) but the color doesn’t change and remain the default button color. I’ve tried to change to a standard color (like red, white), or use a dirrerent color definition (the hex value) but nothing seems to work.
Thank you very much for you reply, adding background:none do the trick!
But i want to understand better the other approach (Style classes):
I understand that i have to crete classes for buttons like this in my style.css file:
My biggest concern is that i don’t know how to remove old style classes; my buttons must have just one class at time. Also my gui updater timer run every 500 milliseconds, but most of the time there is no change on the buttons, so it would be good a method that change only when style class is changed; now i get the name from the button and change it only if it’s different from the one that i have to set.
Maybe i can simply call gtk_style_context_remove_class() with all the possible style classes for the button and in the end add the one desired?