Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Implementing "dark mode" on Ubuntu 24.04 (ok) vs Fedora 42 (not ok)
QtWS25 Last Chance

Implementing "dark mode" on Ubuntu 24.04 (ok) vs Fedora 42 (not ok)

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 132 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christophe R
    wrote last edited by
    #1

    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 to Qt::ColorScheme::Dark or Qt::ColorScheme::Light. I am also implementing the QEvent::ThemeChange in changeEvent(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:
    alt text

    Fedora Gif:
    alt text

    1 Reply Last reply
    0
    • I Offline
      I Offline
      IgKh
      wrote last edited by
      #2

      Hi @Christophe-R and welcome to the forum.

      If the QEvent::ThemeChange is 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 Fusion command line parameter - the Fusion style is shipped with Qt and is known to support dark color scheme hint.

      • Check if the QT_QPA_PLATFORMTHEME environment variable happens to be set - especially with the value qt6ct or qt5ct. qt6ct is 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.

      C 1 Reply Last reply
      0
      • Axel SpoerlA Offline
        Axel SpoerlA Offline
        Axel Spoerl
        Moderators
        wrote last edited by
        #3

        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-scheme
        

        If you find a reliable signal that is not in the list above, you can do the following:

        1. 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.
        2. Start your Qt app and end it again.
        3. Edit the file. It is self explanatory. Add your signal.
        4. Save the file in a good place, e.g. ~/.config
        5. Set the env var QT_QPA_DBUS_SIGNALS to the file, e.g. by adding export QT_QPA_DBUS_SIGNALS_SAVE=/tmp/dbusSigs.json to ~/.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.

        Software Engineer
        The Qt Company, Oslo

        1 Reply Last reply
        1
        • I IgKh

          Hi @Christophe-R and welcome to the forum.

          If the QEvent::ThemeChange is 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 Fusion command line parameter - the Fusion style is shipped with Qt and is known to support dark color scheme hint.

          • Check if the QT_QPA_PLATFORMTHEME environment variable happens to be set - especially with the value qt6ct or qt5ct. qt6ct is 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.

          C Offline
          C Offline
          Christophe R
          wrote last edited by Christophe R
          #4

          @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::ThemeChange is 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 Fusion command 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_PLATFORMTHEME environment variable happens to be set - especially with the value qt6ct or qt5ct. qt6ct is 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_PLATFORMTHEME is not set

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved