Application-wide style with GTKMM4

69 Views Asked by At

I've got some custom styles for widgets that I've put together in a css file. I've loaded this with code like this:

  auto provider = Gtk::CssProvider::create();
  provider->load_from_path("./res/themes/custom/gtk.css");

And then set the style individually for widgets by getting their context and adding the provider with code like this:

  auto ctx = widget->get_style_context();
  ctx->add_provider(provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

But I can't seem to figure out how to just set this for the entire application. Is there a way to set a css/style provider application wide?

1

There are 1 best solutions below

5
Holger On

Update: Just use Gtk::StyleProvider::add_provider_for_display() as noted here: https://gnome.pages.gitlab.gnome.org/gtkmm-documentation/sec-custom-css-names.html


Yes, there is such a way. Unfortunately, I'm currently only working with C and not with gtkmm. However, the difference should not be that big. That's why I recommend the following Q&A. Transferring to Gtkmm will certainly not be a problem.

GTK4 widget customizations using CSS providers do not consistently work

CSS Styles not applied in GTK4 C language