Difference between revisions of "Uniform look for Qt and GTK applications"

From ArchWiki
Jump to: navigation, search
(Clarifying the available approaches to unifying the themes.)
m (QT4 styles)
Line 66: Line 66:
 
* ''Qt Configuration'' (/usr/bin/qtconfig)
 
* ''Qt Configuration'' (/usr/bin/qtconfig)
 
:--> Appearance --> Select GUI Style
 
:--> Appearance --> Select GUI Style
 +
 +
Note that while Qt Configuration allows you to choose the theme, font, etc. for the Qt apps, you can modify more settings with KDE 4 System Settings - e.g. font antialiasing and hinting.
  
 
=== GTK2 styles ===
 
=== GTK2 styles ===

Revision as of 05:59, 15 October 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end

Qt and GTK+ based programs both use a different widget toolkit to render the graphical user interface. Each come with different themes, styles and icon sets by default, among other things, so the "look and feel" differ significantly. This article will help you make your Qt and GTK+ applications look similar for a more streamlined and "integrated" desktop experience.

  • Theme - Collection of a style, an icon theme and a colour theme.
  • Style - Graphical layout; look.
  • Icon Theme - Set of global icons.
  • Colour Theme - Set of global colours that are used in conjunction with the style.

You can choose various approaches:

  • Modify GTK+ and Qt styles separately with the tools listed below for each toolkit and aim for choosing similarly looking themes (style, colours, icons, cursors, fonts).
  • Use a special theme engine, which intermediates the modification of the other graphical toolkit to match your main toolkit:
    • if you work in KDE 4 desktop environment then there is available a GTK-Qt engine, which updates GTK+ configuration files automatically so that GTK+ appearance is similar to the Qt one;
    • if you work in other desktop environments, you can choose QGtkStyle engine (built in Qt), which forces Qt apps to use your GTK+ 2.x theme.

Should you use also GTK+ 3.x toolkit, follow the GTK+ 3.x wiki article to find out how to make it look similar to GTK+ 2.x themes.

Styles for both Qt and GTK+

There are widget style sets available for the purpose of integration, where builds are written and provided for both Qt and GTK+, all major versions included. With these, you can have one look for all applications regardless of the toolkit they had been written with.

KDE4 Oxygen

Oxygen is the QT4 style that installs with KDE4.

There's also a GTK+ version called oxygen-molecule and it's available via AUR. Its goal is to provide a uniform look for GTK+ applications when used under the KDE desktop environment, by using gtk-engine-pixbuf, a dependency, which is also available via AUR. While the AUR package provides some quick and enough instructions to finish the installation, download oxygen-molecule from KDE-look for further documentation and variations.

Another GTK+ port is in the Template:Package Official package. Its primary goal is to ensure visual consistency between GTK2 and qt-based applications running under kde. A secondary objective is to also have a stand-alone nice looking gtk theme that would behave well on other Desktop Environments. Unlike other attempts made to port the kde oxygen theme to gtk, this attempt does not depend on Qt (via some Qt to Gtk conversion engine), nor does render the widget appearance via hard coded pixmaps, which otherwise breaks everytime some setting is changed in kde. There is a package in the AUR for GTK3.

QtCurve

Available for qt4 (kde4), qt3 (kde3), and gtk2 (gnome) in the [extra] repository, this highly-configurable style is the most popular all-rounder. It has many controls for various options, ranging from the appearance of buttons to the shape of sliders. You can install all of them using pacman.

# pacman -S qtcurve-gtk2 qtcurve-kde3 qtcurve-kde4

Others

Similar style sets are those that look like each other - written and provided for both Qt and GTK+ - but are not necessarily from the same developers. You may have to do some minor tweaking to make them look the same. Below is a list:

  • klearlooks (qt3); clearlooks (gtk2)

How do I set styles for each toolkit?

You can use the following methods to change the theme used in each environment.

QT3 styles

  • Using KDE3 Control Center (kcontrol):
--> Appearance & Themes --> Style --> Widget Style
  • kde-config --style [name of style]
  • Qt Configuration (qt3config | /opt/qt/bin/qtconfig)
--> Appearance --> Select GUI Style

QT4 styles

  • Using KDE4 System Settings (/usr/bin/systemsettings)
--> Common Appearance and Behavior --> Application Appearance --> Style --> Widget Style
  • Qt Configuration (/usr/bin/qtconfig)
--> Appearance --> Select GUI Style

Note that while Qt Configuration allows you to choose the theme, font, etc. for the Qt apps, you can modify more settings with KDE 4 System Settings - e.g. font antialiasing and hinting.

GTK2 styles

GTK1 styles

Theme Engines

A Theme Engine can be thought of as a thin layer API which translates themes (excluding icons) between one or more toolkits. These engines add some extra code in the process and it is arguable that this kind of a solution is not as elegant and optimal as using native styles.

GTK-QT-Engine

This one is for use by GTK+ applications running in KDE, which basically means this is for KDE. It applies all Qt settings (styles, fonts, not icons though) to the GTK+ applications and uses the style plug-ins directly. Please note that there are rendering issues with some Qt styles.

# pacman -S gtk-qt-engine

You can access it from:

Control Center (kcontrol) --> Appearance & Themes --> GTK Styles and Fonts

If you want to remove it entirely and every trace of it, you should delete the following files:

  • ~/.gtkrc2.0-kde
  • ~/.kde4/env/gtk-qt-engine.rc.sh
  • ~/gtk-qt-engine.rc

Make it work with OpenOffice

Set (as root):

export SAL_GTK_USE_PIXMAPPAINT=1

into /etc/profile. In KDE4 systemsettings, make sure "use my KDE style in GTK applications" is selected in Appearance > GTK styles and fonts.

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.

Note: Beginning with version 4.5 this style is included in Qt and does not require a separate package anymore.

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.

Another error you may get after launching qtconfig from a shell and selecting the Gtk+ style is:

QGtkStyle was unable to detect the current GTK+ theme.

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

  • Tell Qt where to look for your GTK configuration file by adding the following to your Template:Filename 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.

Template:File

Template:File However it seems in some cases those tools insert only an include directive like Template:File 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.


If these steps do not work, install gconf and run this command:

gconftool-2 --set --type string /desktop/gnome/interface/gtk_theme your-theme-name

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

qtconfig

Other Tricks

KDE file dialogs for GTK2 apps

KGtk is a wrapper script that LD_PRELOAD to force KDE file dialogs (open, save, etc) in GTK2 apps. If you use KDE and prefer its file dialogs over GTK's then you can install kgtk from AUR. Once installed you can run GTK2 applications with kgtk-wrapper in 2 ways (using gimp in the examples).

Calling kgtk-wrapper directly and using the GTK2 binary as an arguement

/usr/local/bin/kgtk-wrapper gimp

OR

Creating a symbolic link to kgtk using the name of the GTK2 binary. Then you can run /usr/local/bin/gimp when you want to run gimp with KDE dialogs.

ln -s /usr/local/bin/kgtk-wrapper /usr/local/bin/gimp
/usr/local/bin/gimp

aMSN GTK or KDE dialogs

aMSN's TK file dialogs are plain looking but no fear there is a plugin that will allow you to use GTK or KDE file dialogs to match your desktop. You can find the plugin on aMSN's Plugin Page

Using custom GTK style

You can use custom styles for specific GTK2 applications. For this, use GTK2_RC_FILES=/path/to/theme/gtk-2.0/gtkrc appname

For example:

GTK2_RC_FILES=/usr/share/themes/QtCurve/gtk-2.0/gtkrc firefox

It will launch firefox with QtCurve theme.

Troubleshooting

Themes not working in GTK apps

If the style or theme engine you setup isn't showing in your GTK apps then it's likely your GTK settings files aren't being loaded for some reason. You can check where your system expects to find these files by doing the following..

$ export | grep gtk

Usually the expected files should be ~/.gtkrc for GTK1, ~/.gtkrc2.0 or ~/.gtkrc2.0-kde for GTK2

Newer versions of gtk-qt-engine use ~/.gtkrc2.0-kde and set the export variable in ~/.kde/env/gtk-qt-engine.rc.sh If you recently removed gtk-qt-engine and are trying to set a GTK theme then you must remove ~/.kde/env/gtk-qt-engine.rc.sh and reboot. Doing this will ensure that GTK looks for it's settings in the standard ~/.gtkrc2.0 instead of ~/.gtkrc2.0-kde