GTK theme does not work properly on Qt Startup Applications

Setup

When a Qt app (KeePassXC, AntiMicroX) is started automatically (via autostart), the GTK theme is not applied.

  • All apps are installed via standard apt packages (I am aware of snap theming issues).
  • I am on Ubuntu 20.04, I use the Yaru dark gtk theme.
  • To apply the GTK theme onto Qt apps, I did the following:
    • Installed the qt5-style-plugins apt package (with all of its dependencies)
    • Added a line to /etc/environment: QT_QPA_PLATFORMTHEME=gtk2
    • This works properly if I start the applications manually

Additional fiddling showed, that on cold start the theme never gets applied properly, however, on a restart, it does work sometimes.

Questions

  • How can I ensure that the dark gtk application theme gets properly used?

  • I would assume that when the autostart happens, some setting is not loaded, hence the breakage. Is there some sort of "service" those apps would have to wait for?

  • Should I try to add delay?

7

2 Answers

What made it work

Added a 1 second startup delay to the autostart desktop files (in ~/.config/autostart/):

[Desktop Entry]
...
X-GNOME-Autostart-Delay=1

This made the apps to start after the X session has properly initialized itself after login. Nothing else was needed (apart from the initial setup).

Notes

  • The QT Configuration tool (shipped in qt5ct apt package) is viable but not necessary.

    • If installed it addes an X session config /etc/X11/Xsession.d/99qt5ct that sets the QT_QPA_PLATFORMTHEME to qt5ct if unset.
    • It enables a wider configuration of Qt theming. I used a minimal ~/.config/qt5ct/qt5ct.conf:
    [Appearance]
    icon_theme=Numix-Circle
    standard_dialogs=gtk2
    style=gtk2
  • For debugging the env of the apps can be checked with this shell command (note, I use fish and not bash): strings /proc/(pidof keepassxc)/environ | grep QT

  • To investigate where environment variables are set one can use these commands:

    # system wide - this was quick
    grep QT_QPA_PLATFORMTHEME --recursive /etc/*
    # per user - this was super slow on my system (*khm* steam *khm*)
    grep QT_QPA_PLATFORMTHEME --recursive ~/*
  • Sources:

On Xubuntu 20.04 LTS

First, install the Qt5 configuration tool with

$ sudo apt install qt5ct

Then, comment out the following line in /etc/X11/Xsession.d/56xubuntu-session by inserting a hash up front:

sudo nano /etc/X11/Xsession.d/56xubuntu-session # QT5 apps to use GTK style #export QT_QPA_PLATFORMTHEME=gtk2

Now, log out and in again. Changes made with MenuSettingsQt5 Settings will take immediate effect.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like