How to access the theming Fonts and Colors on GTK/Gnome

谁说胖子不能爱 提交于 2020-01-23 03:31:07

问题


Lets say i want to write a special text editor widget.

How can i get the default themed colors for texts, selected text and background and which are the users default fonts?

I see that GNOME does define 5 special system fonts and default sizes for this purpose in the GNOME Appearance Configuration dialog, but i haven't found a single word in the GTK documentation how to access them (and the GTK mailing list is a joke:-( ).

Windows and Cocoa both give me dozens of system values.

I found the GtkStyle class but this doesn't seem to be what i need.


回答1:


For the default colors, use something like this:

GdkColor color;
/* Look up the default text color in the theme, use a default 
if it's not defined */
GtkStyle *style = gtk_rc_get_style(my_widget);
if(!gtk_style_lookup_color(style, "text_color", &color))
    gdk_color_parse("black", &color);

There are several names defined for gtk_style_lookup_color(). It's a bit unclear where exactly they are defined, but these are the ones you can define in the GNOME dialog:

  • fg_color
  • bg_color
  • base_color
  • text_color
  • selected_bg_color
  • selected_fg_color
  • tooltip_bg_color
  • tooltip_fg_color

As for the fonts and other system settings, you need to use the GConf library to get these defaults. GTK knows nothing about them, because they're part of the GNOME desktop, not GTK. The default font can be found at the key /desktop/gnome/interface/font_name, for example. If you install the GConf configuration editor, you can browse these keys to see which ones are available; they're all under /desktop/gnome.

PS. What GTK mailing list did you ask on? The one I read doesn't seem to be a joke...



来源:https://stackoverflow.com/questions/2806623/how-to-access-the-theming-fonts-and-colors-on-gtk-gnome

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