1

I'm trying to use Gtk::CssProvider with gtkmm-4.0 but it don't work.

I would like to change background color button.

  //CSS style
  Glib::ustring data = "GtkButton {color: #00ffea;}";
  auto provider = Gtk::CssProvider::create();
  provider->load_from_data(data);
  auto ctx = m_button.get_style_context();
  ctx->add_provider(provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

I think I forget something but I don't understand what.

Any ideas ?

wohlstad
  • 12,661
  • 10
  • 26
  • 39
kramer
  • 177
  • 1
  • 4
  • 15

1 Answers1

1

I add a style class to context, so later uses of the style context will make use of this new class for styling.

Now it works as i want.

  //CSS style
  Glib::ustring data = ".button {background-color: #00FF00;}";
  auto provider = Gtk::CssProvider::create();
  provider->load_from_data(data);
  auto ctx = m_button.get_style_context();
  ctx->add_class("button");
  ctx->add_provider(provider, GTK_STYLE_PROVIDER_PRIORITY_USER);
kramer
  • 177
  • 1
  • 4
  • 15