Implementing "dark mode" on Ubuntu 24.04 (ok) vs Fedora 42 (not ok)
-
Hi,
I am working on a Qt 6.9.0 application and trying to add support for "dark mode" switching from Linux UI.
My application is using
QGuiApplication::styleHints()->colorScheme()to figure out whether the OS is set toQt::ColorScheme::DarkorQt::ColorScheme::Light. I am also implementing theQEvent::ThemeChangeinchangeEvent(QEvent *event).The detection is working just fine everywhere (Windows, macOS, Linux (any distro).
However, on Fedora is the dark theme update that is not working and even if I detect the dark theme switch, the theme remains visually light. I tried to explicitly call
app.styleHints()->setColorScheme(Qt::ColorScheme::Dark);but still, the UI (except for the title bar) remains light.Any idea what's going on with Fedora ? I only tried with Fedora and Ubuntu so I am concerned this is a problem on other distributions but I don't understand why.
My Fedora is using Gnome 48 and my Ubuntu is using Gnome 46.
Ubuntu Gif:

Fedora Gif:
-
Hi @Christophe-R and welcome to the forum.
If the
QEvent::ThemeChangeis correctly delivered to your top level window, I think that the Qt style in use in your Fedora installation might not have a dark palette (style hints are only hints after all - the actual style class must respect them).-
Try running your application with the
-style Fusioncommand line parameter - the Fusion style is shipped with Qt and is known to support dark color scheme hint. -
Check if the
QT_QPA_PLATFORMTHEMEenvironment variable happens to be set - especially with the valueqt6ctorqt5ct.qt6ctis a great tool for getting Qt apps to blend in with GTK based desktop environments, but it it messes with palettes pretty heavily to achieve that.
-
-
A. Reaction to changes of the system's color scheme is one thing.
Qt listens to the following DBus signals and updates the color scheme if one of them is fired.
Fedora (not a supported Distro btw.) doesn't seem to fire one of the signals.
You can find that out by running dbusmon on your system and see what gets fired when you change the color scheme.org.kde.kdeglobals.KDE, widgetStyle org.kde.kdeglobals.General ColorScheme org.gnome.desktop.interface gtk-theme org.freedesktop.appearance color-schemeIf you find a reliable signal that is not in the list above, you can do the following:
- Set the env var QT_QPA_DBUS_SIGNALS_SAVE to a writeable, non-existing json file e.g.
export QT_QPA_DBUS_SIGNALS_SAVE=/tmp/dbusSigs.json. - Start your Qt app and end it again.
- Edit the file. It is self explanatory. Add your signal.
- Save the file in a good place, e.g. ~/.config
- Set the env var QT_QPA_DBUS_SIGNALS to the file, e.g. by adding
export QT_QPA_DBUS_SIGNALS_SAVE=/tmp/dbusSigs.jsonto~/.profile
B. Manually setting the color scheme is another thing
It's supported in the GTK3 and KDE platform themes. It's not supported in the bare Gnome platform theme.
The support for GTK3 and KDE has been added earlier this year and they have been picked to 6.9. I am not sure, 6.9.0 had it in already.
Support should be added in the Gnome theme as well.
You could write a bug report about it. - Set the env var QT_QPA_DBUS_SIGNALS_SAVE to a writeable, non-existing json file e.g.
-
Hi @Christophe-R and welcome to the forum.
If the
QEvent::ThemeChangeis correctly delivered to your top level window, I think that the Qt style in use in your Fedora installation might not have a dark palette (style hints are only hints after all - the actual style class must respect them).-
Try running your application with the
-style Fusioncommand line parameter - the Fusion style is shipped with Qt and is known to support dark color scheme hint. -
Check if the
QT_QPA_PLATFORMTHEMEenvironment variable happens to be set - especially with the valueqt6ctorqt5ct.qt6ctis a great tool for getting Qt apps to blend in with GTK based desktop environments, but it it messes with palettes pretty heavily to achieve that.
@IgKh said in Implementing "dark mode" on Ubuntu 24.04 (ok) vs Fedora 42 (not ok):
Hi @Christophe-R and welcome to the forum.
If the
QEvent::ThemeChangeis correctly delivered to your top level window, I think that the Qt style in use in your Fedora installation might not have a dark palette (style hints are only hints after all - the actual style class must respect them).- Try running your application with the
-style Fusioncommand line parameter - the Fusion style is shipped with Qt and is known to support dark color scheme hint.
I am using in my C++ code:
app.setStyle("fusion");- Check if the
QT_QPA_PLATFORMTHEMEenvironment variable happens to be set - especially with the valueqt6ctorqt5ct.qt6ctis a great tool for getting Qt apps to blend in with GTK based desktop environments, but it it messes with palettes pretty heavily to achieve that.
QT_QPA_PLATFORMTHEMEis not set -