6

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?

  • By any chance, are these installed as snap? Edit your question to add this information – Archisman Panigrahi Dec 07 '20 at 11:21
  • @ArchismanPanigrahi No - standard apt installs. snap theming is a different problem I gave up on (some say its work in progress) – MrMeszaros Dec 07 '20 at 11:29
  • 1
    The mentioned apps are qt-applications, not GTK... – mook765 Dec 13 '20 at 23:39
  • 1
    Check out the package qt5ct, it's a qt5 configuration tool, that might be helpful for you. – mook765 Dec 13 '20 at 23:51
  • 1
    I should point out that Qt-based applications don't inherit GTK themes - they use Qt themes. Just like GTK applications don't use Qt themes. Known issue between those types of applications using different themeing mechanisms. – Thomas Ward Dec 14 '20 at 13:59
  • @mook765 Thanks, you were right - in the meantime I did some local testing. However, I had no success with qt5ct - the theme still does not apply properly with autostart. Do You know more about autostart and theming please share some sources! – MrMeszaros Dec 14 '20 at 15:11
  • Does it work when you add a startup delay? Also, there may be issues with qt5ct. You can try Kvantum, which is modern, and very actively developed. See https://askubuntu.com/a/1234625/124466 – Archisman Panigrahi Dec 17 '20 at 12:03

2 Answers2

2

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:

0

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.

Serge Stroobandt
  • 5,268
  • 1
  • 48
  • 59