Setup
When a Qt app (KeePassXC, AntiMicroX) is started automatically (via autostart), the GTK theme is not applied.
- All apps are installed via standard
aptpackages (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-pluginsapt 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?
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=1This 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
qt5ctapt package) is viable but not necessary.- If installed it addes an X session config
/etc/X11/Xsession.d/99qt5ctthat sets theQT_QPA_PLATFORMTHEMEtoqt5ctif 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 QTTo 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?
On Xubuntu 20.04 LTS
First, install the Qt5 configuration tool with
$ sudo apt install qt5ctThen, 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=gtk2Now, log out and in again. Changes made with Menu → Settings → Qt5 Settings will take immediate effect.