kramer
kramer

Reputation: 327

How to use Gtk::CssProvider with gtkmm-4.0?

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 ?

Upvotes: 2

Views: 673

Answers (1)

kramer
kramer

Reputation: 327

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);

Upvotes: 2

Related Questions