Does anyone know how to change button color using css? I need to change it depending on if a function returns true/false. I've found this piece of code but i cannot change the color of the button. The color of the button becomes blue.
GdkDisplay *display;
GdkScreen *screen;
GtkCssProvider *provider;
GtkWidget *testBtn;
//create a button
testBtn = gtk_button_new_with_label("test");
//give button ID
gtk_widget_set_name(GTK_WIDGET(testBtn), "testBtnNeutral");
//Create objects.
provider = gtk_css_provider_new();
display = gdk_display_get_default();
screen = gdk_display_get_default_screen(display);
//Connect screen with provider.
gtk_style_context_add_provider_for_screen(screen,
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
//Give button color.
gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(provider), "#testBtnNeutral {background:blue; color:white} \n #testBtnFail {background:red; color:white} \n #testBtnSuccess {background:green; color:white}", -1 , NULL);
Function where I'm trying to change button color.
static void testFunction(VariablesThatCouldBeUsedInFunctions *StructPointer){
if(bTestElectricFunctions){
gtk_widget_set_name(GTK_WIDGET(StructPointer->testBtn), "testBtnSuccess");
//Gtk-CRITICAL **: gtk_widget_set_name: assertion 'GTK_IS_WIDGET (widget)' failed
}
else{
printf("untrue\n");
}
}