如何在Gtkmm3中使用CssStyleProvider
我正在使用 gtkmm3 用 c++ 进行编程。我想更改程序中的一些字体。我在 gtkmm 文档和 gtk+ 文档中阅读了有关 CssStyleProvider、StyleContext 的所有内容,但我无法使其工作,也找不到任何相关教程。我正在尝试那样,
Glib::ustring data;
data="GtkMenuBar, GtkMenuItem {font-name: Sans 6}"; /*tried with semi-colon, too*/
Glib::RefPtr<Gtk::CssProvider> asd = Gtk::CssProvider::create();
Glib::RefPtr<Gtk::StyleContext> asd2 = Gtk::StyleContext::create();
asd->load_from_data(data);
asd2->add_provider(asd, 0); /*also tried different priorities*/
也尝试过那样
Glib::ustring data;
data="GtkMenuBar, GtkMenuItem {font-name: Sans 6}"; /*tried with semi-colon, too*/
Glib::RefPtr<Gtk::CssProvider> asd = Gtk::CssProvider::create();
Glib::RefPtr<Gdk::Screen> screen;
Glib::RefPtr<Gtk::StyleContext> asd2 = Gtk::StyleContext::create();
asd->load_from_data(data);
(mainWindow.get())->get_property("screen", screen);
asd2->add_provider(screen, asd, 0); /*also tried different priorities*/
,我在运行主窗口之前和运行之后尝试了这些,但我没有运气。任何帮助表示赞赏。
I'm programming in c++ with gtkmm3. I want to change some fonts in my program. I read all the things about CssStyleProvider, StyleContext in gtkmm documentation and also in gtk+ documentaion but i couldn't make it work and couldn't find any tutorial about that. I'm trying like that
Glib::ustring data;
data="GtkMenuBar, GtkMenuItem {font-name: Sans 6}"; /*tried with semi-colon, too*/
Glib::RefPtr<Gtk::CssProvider> asd = Gtk::CssProvider::create();
Glib::RefPtr<Gtk::StyleContext> asd2 = Gtk::StyleContext::create();
asd->load_from_data(data);
asd2->add_provider(asd, 0); /*also tried different priorities*/
also tried like that
Glib::ustring data;
data="GtkMenuBar, GtkMenuItem {font-name: Sans 6}"; /*tried with semi-colon, too*/
Glib::RefPtr<Gtk::CssProvider> asd = Gtk::CssProvider::create();
Glib::RefPtr<Gdk::Screen> screen;
Glib::RefPtr<Gtk::StyleContext> asd2 = Gtk::StyleContext::create();
asd->load_from_data(data);
(mainWindow.get())->get_property("screen", screen);
asd2->add_provider(screen, asd, 0); /*also tried different priorities*/
And I tried these before running my main window and after running it but i have no luck. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否也尝试过使用宏 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION 而不是 0?
对我有用,也在 Windows 上。
例子:
Have you also to tried to use the macro GTK_STYLE_PROVIDER_PRIORITY_APPLICATION instead of 0?
Works for me, also on Windows.
Example:
我不知道 gtkmm 和 css,但是网络上的 css 需要在
font-name:Sans 6
之后有一个;
除此之外,你所拥有的一切看起来都是正确的GTK::CssProvider 参考
I don't know about gtkmm and css, but css on the web requires a
;
afterfont-name:Sans 6
Other than that, everything you have looks right based on the GTK::CssProvider reference