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
- Installed the
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?
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 theQT_QPA_PLATFORMTHEME
toqt5ct
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
- If installed it addes an X session config
-
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:
- Comments under this question
- How to determine where an environment variable came from?
- How can I delay a specific program on startup?