How to use CssStyleProvider in Gtkmm3

做~自己de王妃 提交于 2019-12-04 03:25:43
user1412363

Have you also to tried to use the macro GTK_STYLE_PROVIDER_PRIORITY_APPLICATION instead of 0?

asd2->add_provider(screen, asd, macro GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

Works for me, also on Windows.

Example:

int main(int argc, char **argv) {

  Main app(argc, argv);
  Glib::ustring data = "GtkLabel {color: #ff00ea;font: Comic Sans MS 12}";
  auto css = CssProvider::create();
  if(not css->load_from_data(data)) {
      cerr << "Failed to load css\n";
      std::exit(1);
  }
  Label label("test");
  Window win;
  auto screen = Gdk::Screen::get_default();
  auto ctx = label.get_style_context();
  ctx->add_provider_for_screen(screen, css, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
  win.add(label);
  win.show_all();

  app.run(win);
  return 0;
}

I don't know about gtkmm and css, but css on the web requires a ; after font-name:Sans 6

Other than that, everything you have looks right based on the GTK::CssProvider reference

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!