问题
I've started working with GTK+ and Vala and am having a hard time finding documentation on creating custom buttons (totally new looking buttons). In fact now that I think about it, every GTK+ application has that distinct look that gives away that it's a GTK+ app. Is it difficult to create a totally new look for my application if I decide to use GTK+?
回答1:
You can use the GTK2_RC_FILES
environment variable to assign a special theme to (only) your application.
For example, you can create a batch starter (Windows) like so:
set GTK2_RC_FILES=%GTK_HOME%\share\themes\slickness-black\gtk-2.0\gtkrc
launch.exe
Or in Linux (haven't tried that one):
env GTK2_RC_FILES=/usr/share/themes/slickness-black/gtk-2.0/gtkrc ./launch
Hint: Don't trust in GTK_HOME to be set, rather use the absolute path of the GTK+ installation. If you install a special theme with your application, it might be possible to use a relative path (relative to the installation path of your app). Then you should make sure that the theme is supported by one of the most common theme engines because usually not all of them are installed (especially on Windows, where GTK installers are a mess).
回答2:
It's made difficult on purpose, because "that distinct GTK look" is the whole point. GTK applications generally place a lot of value on usability, accessibility, and user experience. You, the application programmer, should concentrate on the content of your application, and let the user choose a theme they like. If you make custom buttons, then they might be too narrow to fit the translated labels for a user using your application in another language. Or maybe your custom buttons look really horrible on someone's preferred window background color.
回答3:
RC code has been replaced in gtk+3. It now supports css for styling this may give you what you need.
http://developer.gnome.org/gtk3/3.1/gtk-migrating-GtkStyleContext.html
http://thegnomejournal.wordpress.com/2011/03/15/styling-gtk-with-css/
h te te p://kalmbach.wordpress.com/2011/03/12/gtk-3-0-client-side-theme/
回答4:
@gtksharp:
string fileName = @"/usr/valapp/gtkrc3";
Gtk.Rc.AddDefaultFile(fileName);
Gtk.Rc.Parse(fileName);
来源:https://stackoverflow.com/questions/3956796/gtk-application-specific-skin-possible