Search code examples
cgtk

GTK treeview: disable highlight when selected


I try to disable highlight on a row when it is selected for a GtkTreeView widget (default is blue background and white text color). I tried to change the STATE_SELECTED with

GtkWidget   *treev_iew;
GdkColor black;
GdkColor white;

gdk_color_parse ("white", &white);
gdk_color_parse ("black", &black);
...
treeview = gtk_tree_view_new();
...
gtk_widget_modify_text(GTK_WIDGET(tree_view),GTK_STATE_SELECTED,&black);
gtk_widget_modify_bg(GTK_WIDGET(tree_view),GTK_STATE_SELECTED, &white);
...

but this doesn't seem to work. The background changes to white, but the font color stays white (not readable!). Any idea why?


Solution

  • I reviewed the GTK widget definition for available functions (FYI, the version I reviewed was GTK3 in case you are working with a different version of GTK). In there, it mentions that the function "gtk_widget_modify_text()" is deprecated and the "gtk_widget_override_color() function should be used instead. You might try that substitution.

    Please note that as of version 3.16, this function is also deprecated but probably will still work. The direction forward for handling attributes such as background colors, foreground colors, text colors, and so forth are through the use CSS definitions coupled with CSS providers within a program.

    Hope that helps.

    Regards.