问题
I want to set the font to be used by a particular Gtk+ 3 application. How can it be done?
I know I can set the font to be used by all Gtk+ 3 applications in the file $XDG_CONFIG_HOME/gtk-3.0/settings.ini, but I do not know how the font can be set for only a specific application.
Edit: I am not developing the application. I just want to run it with a font size different from the current one set for the desktop.
回答1:
Use GtkCssProvider. You don't say what language you're using GTK in, so no code example, but here are the steps:
- create a
GtkCssProvider - add a CSS string to it (such as
*{font-family:'Comic Sans';}) withgtk_css_provider_load_from_data() - activate it with
gtk_style_context_add_provider_for_screen(). (You probably want to use the default screen,gdk_screen_get_default().)
回答2:
Modify the file ~/.config/gtk-3.0/settings.ini according to your wishes for your specific application (i.e. font, font-size, theme, etc.).
Save it under ~/.config/somewhereelse/gtk-3.0.
Run the application with XDG_CONFIG_HOME=$HOME/.config/somewhereelse your-application
来源:https://stackoverflow.com/questions/32795957/font-setting-for-a-specific-gtk-application