How to change style of header of treeview columns in gtk3?

I am trying to change background color of header of treeview column in gtk3. The color of the cells changes but not the header and I get two different errors. Here is what I have done with comments as explanation.


GtkTreeViewColumn *column20 = gtk_tree_view_get_column(treeview2, 0); // Gets first column of 2nd //tree view
gtk_tree_view_column_set_widget(column20, treeview2header); //sets the header widget
GtkWidget *treeview2headerget = gtk_tree_view_column_get_widget(column20); //gets the header //widget
contexttreeview2header = gtk_widget_get_style_context (treeview2headerget); //gets the widget's context
GtkCssProvider *providertreeview2header =gtk_css_provider_new();gtk_css_provider_load_from_path (providertreeview2header, "styles.css", NULL);
gtk_style_context_add_provider (contexttreeview2header,                                     GTK_STYLE_PROVIDER(providertreeview2header),                                     GTK_STYLE_PROVIDER_PRIORITY_USER);
gtk_widget_set_name (treeview2headerget, "column201");

The styles.css is:

#column201 {background-color: rgb(70, 226, 150);}

This gives the error:

Segmentation fault

Now in header_.c if i change the following line:



gtk_tree_view_column_set_widget(column20, NULL);

the documentation states I should get a GtkLabel.
So I remove the following:

gtk_widget_set_name (treeview2headerget, "column201");

and in styles.css I write:

label * {background-color: rgb(70, 226, 150);}

Now Segmentation fault is gone and I get the window to open but color doesnt change and in terminal I get:

Gtk-CRITICAL **: 10:33:03.642: gtk_widget_get_style_context: assertion 'GTK_IS_WIDGET (widget)' failed

Gtk-CRITICAL **: 10:33:03.647: gtk_style_context_add_provider: assertion 'GTK_IS_STYLE_CONTEXT (context)' failed

How do I get the color to change? Kindly help me out.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.