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. Switching between a light and dark color scheme
Forum Updated to NodeBB v4.3 + New Features

Switching between a light and dark color scheme

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 908 Views 2 Watching
  • 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.
  • Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    See https://doc.qt.io/qt-6/qstylehints.html#setColorScheme

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    0
    • l3u_L Offline
      l3u_L Offline
      l3u_
      wrote on last edited by
      #3

      Thanks a lot, seems like all I found was pre-6.8!

      1 Reply Last reply
      0
      • l3u_L Offline
        l3u_L Offline
        l3u_
        wrote on last edited by l3u_
        #4

        Well okay, I tried to add it. E.g. switching to dark in light mode via

        QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Dark);
        

        it compiles, it runs … but nothing happens when I call it. Which isn't particularily surprising when one looks at the code of QStyleHints:

        void QStyleHints::setColorScheme(Qt::ColorScheme scheme)
        {
            if (!QCoreApplication::instance()) {
                qWarning("Must construct a QGuiApplication before accessing a platform theme hint.");
                return;
            }
            if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
                theme->requestColorScheme(scheme);
        }
        

        which then calls:

        void QPlatformTheme::requestColorScheme(Qt::ColorScheme scheme)
        {
            Q_UNUSED(scheme);
        }
        

        Is this currently only some placeholder to be implemented later on, or did I miss something?

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #5

          It is working fine for at least 6.9 and up. You look into the default implementation instead the windows platform integration...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • l3u_L Offline
            l3u_L Offline
            l3u_
            wrote on last edited by
            #6

            Ah okay! Well, however, apparently Linux still lacks the implementation. At least here on Gentoo and 6.9.1, it doesn't work …

            I 1 Reply Last reply
            0
            • l3u_L l3u_

              Ah okay! Well, however, apparently Linux still lacks the implementation. At least here on Gentoo and 6.9.1, it doesn't work …

              I Online
              I Online
              IgKh
              wrote last edited by
              #7

              @l3u_ said in Switching between a light and dark color scheme:

              Well, however, apparently Linux still lacks the implementation. At least here on Gentoo and 6.9.1, it doesn't work …

              requestColorScheme is part of the platform theme, which on Linux is different for every environment. What is your desktop environment/WM and kind of display server protocol (X11 / Wayland)?

              1 Reply Last reply
              0
              • l3u_L Offline
                l3u_L Offline
                l3u_
                wrote last edited by l3u_
                #8

                I run Plasma/KDE on X11, stable Gentoo

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

                  KDE ships its own platform theme plugin, see here.

                  As far as I can see, it doesn't re-implement requestColorScheme(), which is probably why your app is unresponsive to programmatic colour scheme changes. You could ask for this feature (or even contribute it) on the KDE development mailing list.

                  As an alternative, you can force-load another platform theme, where requestColorScheme() is implemented, e.g. the GTK3 theme. You can do so by setting the environment variable QPA_PLATFORM_THEME=gtk3.

                  Software Engineer
                  The Qt Company, Oslo

                  1 Reply Last reply
                  1
                  • l3u_L Offline
                    l3u_L Offline
                    l3u_
                    wrote last edited by
                    #10

                    Okay, the take home message is that sooner or later, one will be able to reliably switch dark/light using pure Qt, the infrastructure is there – but not everybody has implemented it yet. For KDE, we should add this. Our own stuff can already switch themes and colors for quite some time, but that uses KDE/Plasma internals which are not accessible for plain Qt (unless one depends on KDE libraries of course). I'll file a feature request. Thanks for the clarification!

                    1 Reply Last reply
                    0
                    • l3u_L Offline
                      l3u_L Offline
                      l3u_
                      wrote last edited by
                      #11

                      Here we are: https://bugs.kde.org/show_bug.cgi?id=509488

                      1 Reply Last reply
                      2

                      • Login

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