Highlight a default GtkButton


Currently, when a button in my app has the focus (i.e. will trigger with RETURN), it has a tiny tiny highlight around the perimeter of the button, that is very hard to see. I would like to make this more obvious either by:

  1. making the perimeter highlight bigger/brighter
  2. by coloring the default button.

I have tried the code below, but since it does not work, I may be barking up the wrong tree.

GTKUseButtonHighlight(GtkWidget *button)
  GtkCssProvider *cssProvider = gtk_css_provider_new();
  char *data = "button {.suggested-action;}";
  gtk_style_context_add_provider(gtk_widget_get_style_context( button),
  return 0;

I get a warning from the theme about a missing “;”, but I am not sure that I am on the right path anyway. Can anyone advise me?


That’s not valid CSS.

If you want to add a style class to your widget, you should use gtk_widget_add_css_class.

Thanks for that suggestion. I suspect that that is a GTK4 call as I am using GTK3+ at the moment, and I get an undefined reference error. Is there a similar feature in GTK3+?


Always remember to specify which version of GTK you’re using. This way people can answer your question without guessing.

In GTK3 you will need to retrieve the GtkStyleContext for the widget using gtk_widget_get_style_context and then use gtk_style_context_add_class.

Remember that if the CSS selector is .class-name, the class name to pass to this function is going to be class-name, i.e. without the leading dot.

Many thanks Emmanuele!

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