How can I get Qt5 applications to use the GTK theme in Ubuntu 17.04?

35,516

Solution 1

The look and feel of Qt5 applications is determined by platform themes and styles. The platform theme is responsible for icons, fonts, etc. and the style controls how widgets are rendered. I think you'll find your application such as Qt Creator is using the GTK3 platform theme as standard.

The problem has occurred since Qt5.7. In this release, the GTK2 platform theme and style was removed and replaced with the GTK3 platform theme. I've recently been in discussion with the Qt developers and it appears there isn't a GTK3 style to complement the platform theme and there are currently no plans to implement this in the future. Therefore, on Ubuntu, the default style is "Fusion" using the GTK3 platform theme.

There are a couple of methods to add a native style as follows:

  1. The old GTK2 platform theme and style are still available in a separate package called qtstyleplugins that can be downloaded here. Unfortunately, the GTK2 style is not compatible with the GTK3 platform theme. If you want to use the GTK2 style you will have to use the GTK2 platform theme. This will mean your dialogs etc. do not look native in Ubuntu 17.04. However, you may prefer it to "Fusion".
  2. You didn't state what desktop environment you are using. There is a third party platform theme and style called QGnomePlatform available here and adwaita-qt available here. This provides a fully native look and feel when using Ubuntu Gnome.

For Qt Creator, I'm not 100% sure if it uses global theme/style locations. You may have to install them in {Qt_installation_folder}\Tools\QtCreator\lib\Qt\Plugins\platformthemes\ and {Qt_installation_folder}\Tools\QtCreator\lib\Qt\Plugins\styles\.

Solution 2

Apart from qt5ct you also need to install qt5-style-plugins package, then you should get the 'gtk2' theme in qt5ct

sudo apt-get install qt5-style-plugins

And, as per the qt5ct documentation, don't forget to set QT_QPA_PLATFORMTHEME=qt5ct in /etc/X11/Xsession.d/56xubuntu-session and/or /etc/environment

Share:
35,516

Related videos on Youtube

Philipp Ludwig
Author by

Philipp Ludwig

Building stuff with Linux, C++ and sometimes Rust.

Updated on September 18, 2022

Comments

  • Philipp Ludwig
    Philipp Ludwig over 1 year

    Since I updated to Ubuntu 17.04, Qt5 applications (such as Qt Creator) won't use the GTK theme anymore. I tried to change this using qt5ct, but it only has the styles Fusion and Windows available, even though that the package qt5-gtk-platformtheme is installed.

    How can this be fixed?

    Edit: I'm using Unity.

  • Philipp Ludwig
    Philipp Ludwig about 7 years
    Thanks for the detailed explanation. I wouldn't mind Fusion so much if the font rendering would not be so horrible. Is there an open bug somewhere about this?
  • gsxruk
    gsxruk about 7 years
    The fonts have not appeared poor from what I've seen on my system. Do you have a screenshot of this?
  • Philipp Ludwig
    Philipp Ludwig about 7 years
    I've uploaded a screenshot here: imgur.com/a/u34W6 Left is Qt Creator, right is a vim session in gnome-terminal. I agree that is very subtle, but the Qt fonts just feel blurry (or blurrier?) to me. Both applications are set to Ubuntu Mono 12.
  • gsxruk
    gsxruk about 7 years
    I see what you mean, but I agree it's subtle. Sorry, don't know what to suggest on that one.
  • Philipp Ludwig
    Philipp Ludwig about 7 years
    In case you are interested: I've had better results with infinality on funtoo, but as far as I know this patchset isn't properly maintained anymore. Anyway, the fonts look much better on my laptop, which has an IPS panel, so maybe I just need to upgrade my 7 year old display on my desktop. Thanks for your help!
  • DMT
    DMT over 6 years
    This answer works for me, without installing qt5ct.
  • Gyll
    Gyll over 6 years
    yes, installing only qt5-style-plugins (i.e. w/o qt5ct) works just fine for styling qt5.7+ with gtk2. qt5ct is only needed if you want to also use other styles for qt5.7+ than gtk2
  • Gyll
    Gyll about 5 years
    btw, being sick and tired of inconsistencies on my desktop, i ended up putting together a theme of my own, you might want to check it out if inconsistencies drive your nuts: xfce-evolution.sourceforge.net
  • 71GA
    71GA almost 3 years
    This however stops working when you try to use wayland. I set QT_QPA_PLATFORMTHEME=qt5ct and QT_QPA_PLATFORM=wayland in /etc/environment and I can then use qt5ct to change the default themes that come preinstalled with qt5ct. Then I install qt5ct-style-plugins and new theme i.e. gtk2 appears in qt5ct but it does not do anything when I select it!
  • 71GA
    71GA almost 3 years
    SUCESS! After I installed lxappearance and choose the desired GTK2 theme (any that are inside /usr/share/themes) inside lxappearance , chosen theme was automatically adopted by qt5ct. This was the missing step! Well qt5ct did automatically adopt the theme even without lxappearance, but default theme was ugly! This also works for pyqt5 applications like convertall!