Make Qt Apps follow System Light/Dark Style in Ubuntu 22.04

Last updated: October 7, 2023 — Leave a comment

This simple tutorial shows how to make Qt-based applications automatically change their theme to be light or dark, according to system color style in Ubuntu 22.04.

Ubuntu has global option to change system color scheme to light or dark since 22.04. However, Qt apps (e.g., VirtualBox, qBittorrent, keepassxc) always stick to their own color style, except for the title-bar.

To make Qt applications fit into GNOME environment as well as possible, Fedora Linux is working on some projects to do the job.

So far, QGnomePlatform theme is a good choice, though the upstream has been switching to QAdwaitaDecorations.

With it, your Qt applications will:

  • take use GNOME Adwaita style theme.
  • automatically switch to light or dark, depends on system color style.
  • have native header-bar and borders, even when running against Wayland

Install the QGnomePlatform Theme

The QGnomePlatform Theme package is available in system repositories since Ubuntu 23.04. Sadly, it’s built for Qt5 applications only!

For Ubuntu 22.04, I’ve made it into this unofficial PPA for amd64, arm64/hf architectures support.

To install it, press Ctrl+Alt+T on keyboard to open terminal. Then, run the 2 commands below one by one:

  1. Run command to add the PPA:
    sudo add-apt-repository ppa:ubuntuhandbook1/qgnomeplatform

  2. Then install the theme package:
    sudo apt install qgnomeplatform-qt5

NOTE: Ubuntu 23.04 and Ubuntu 23.10 users can directly run the last apt install command without adding PPA.

After installation, the new theme package should be automatically taken use for your Qt (qt5) apps. Some Qt apps use their own theme options, you have to open their ‘Preferences’ or ‘Settings’ dialog to switch to default or system theme.

If NOT, open ‘Files’ and press Ctrl+H to view hidden files. Then, click editing the ‘.profile‘ file and adding the new line below in the end:

export QT_QPA_PLATFORMTHEME='gnome'

Finally, log out and back in to apply change.

Uninstall:

You can remove the Ubuntu PPA after installation, since it will no longer receive updates. To do so, open terminal and run command:

sudo add-apt-repository --remove ppa:ubuntuhandbook1/qgnomeplatform

To remove the theme package, run:

sudo apt remove --autoremove qgnomeplatform-qt5

Also remember to restore the .profile file in your user home.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1 |

No Comments

Be the first to start the conversation.

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

*