Friday, June 18, 2010

Make qt apps look better in an almost gtk only desktop

QGtkStyle

This is a Qt style which intends to make applications blend perfectly into the GNOME desktop environment by using GTK to render all components. To use this style you must have at least GTK+ 2.0 and Qt 4.3, although Qt 4.4 or higher is preferred.

Having trouble making your Qt applications use QGtkStyle?

Qt won't apply QGtkStyle correctly if GTK is using the GTK-QT-Engine. Qt determines whether the GTK-QT-Engine is in use by reading the GTK configuration files listed in the environmental variable GTK2_RC_FILES. If the environmental variable is not set properly, Qt assumes you are using the GTK-QT-Engine, sets QGtkStyle to use the style GTK style Clearlooks, and outputs an error message:

QGtkStyle cannot be used together with the GTK_Qt engine.

Users of Openbox and other non-GNOME environments may encounter this probem. Here is a solution:

  • Tell Qt where to look for your GTK configuration file by adding the following to your .xinitrc file:
    • To add multiple paths, separate them with colons.
    • The $HOME part will expand to be path to your user's home directory. Using the ~ shortcut won't work.
File: .xinitrc
...
export GTK2_RC_FILES="$HOME/.gtkrc-2.0"
...
File: .gtkrc-2.0
...
gtk-theme-name="Crux"
...

However it seems in sume cases those tools insert only an include directive like

File: .gtkrc-2.0
...
include "/usr/share/themes/SomeTheme/gtk-2.0/gtkrc"
...
which apparently is not recognized by all versions of QGtkStyle. You can hotfix this problem by inserting the gtk-theme-name manually in your .gtkrc-2.0 like above, note however that Gtk2-style-change applications might overwrite that change when you use them.

To choose your GTK theme for QT apps you must run:

qtconfig

source: http://wiki.archlinux.org/index.php/Uniform_Look_for_QT_and_GTK_Applications#GTK-QT-Engine

Blog Archive