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. Force light mode on system set to dark mode
Forum Updated to NodeBB v4.3 + New Features

Force light mode on system set to dark mode

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 15.9k 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.
  • C Offline
    C Offline
    clarify
    wrote on last edited by clarify
    #1

    Hi folks,
    I generally keep my computer in dark mode,
    but there is one Qt app where there is a QTextEdit
    and I really need it (alone) to be in light mode.
    Is there a way to set the light theme for only 1 widget?
    I tried setting the style sheet but there are many
    colors in use, and I find that the QTextEdit is
    automatically switching many other them to
    dark mode equivalents. I'm using C++.
    Thanks.

    Axel SpoerlA 1 Reply Last reply
    1
    • C clarify

      Hi folks,
      I generally keep my computer in dark mode,
      but there is one Qt app where there is a QTextEdit
      and I really need it (alone) to be in light mode.
      Is there a way to set the light theme for only 1 widget?
      I tried setting the style sheet but there are many
      colors in use, and I find that the QTextEdit is
      automatically switching many other them to
      dark mode equivalents. I'm using C++.
      Thanks.

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @clarify
      You can set any palette on any widget at any time.
      See here.

      Software Engineer
      The Qt Company, Oslo

      C 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        @clarify
        You can set any palette on any widget at any time.
        See here.

        C Offline
        C Offline
        clarify
        wrote on last edited by
        #3

        @Axel-Spoerl How can I determine the default palette for Light Mode?

        Axel SpoerlA 1 Reply Last reply
        0
        • C clarify

          @Axel-Spoerl How can I determine the default palette for Light Mode?

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by Axel Spoerl
          #4

          @clarify
          It depends on the platform theme, how the standard palette for a light color scheme looks like. It differs by OS. On Linux, it also depends on the theming applied to Gnome or KDE.

          If you are building for a specific platform setup, I'd probably start by switching to light mode, and dumping a default constructed palette: qDebug() << QPalette(). I'd use the output to hard code my own light-enforced palette.

          If the application is cross-platform, you can blend that palette by dumping it on each platform and making the light-enforced palette platform-dependent. Alternatively, you could use the fusion palette. I'd consider that as the best possible compromise for a uniform, cross-platform palette.
          See method qt_fusionPalette() in src/gui/kernel/qplatformtheme.cpp.

          Software Engineer
          The Qt Company, Oslo

          C 1 Reply Last reply
          1
          • Axel SpoerlA Axel Spoerl

            @clarify
            It depends on the platform theme, how the standard palette for a light color scheme looks like. It differs by OS. On Linux, it also depends on the theming applied to Gnome or KDE.

            If you are building for a specific platform setup, I'd probably start by switching to light mode, and dumping a default constructed palette: qDebug() << QPalette(). I'd use the output to hard code my own light-enforced palette.

            If the application is cross-platform, you can blend that palette by dumping it on each platform and making the light-enforced palette platform-dependent. Alternatively, you could use the fusion palette. I'd consider that as the best possible compromise for a uniform, cross-platform palette.
            See method qt_fusionPalette() in src/gui/kernel/qplatformtheme.cpp.

            C Offline
            C Offline
            clarify
            wrote on last edited by
            #5

            @Axel-Spoerl said in Force light mode on system set to dark mode:

            qDebug() << QPalette()

            FYI The expression "qDebug() << QPalette()" only produces errors.
            I'm surprised there isn't a simple way to set a widget to light or dark mode, even if the colors originate from the system.

            Axel SpoerlA 1 Reply Last reply
            0
            • C clarify

              @Axel-Spoerl said in Force light mode on system set to dark mode:

              qDebug() << QPalette()

              FYI The expression "qDebug() << QPalette()" only produces errors.
              I'm surprised there isn't a simple way to set a widget to light or dark mode, even if the colors originate from the system.

              Axel SpoerlA Offline
              Axel SpoerlA Offline
              Axel Spoerl
              Moderators
              wrote on last edited by
              #6

              @clarify said in Force light mode on system set to dark mode:

              @Axel-Spoerl said in Force light mode on system set to dark mode:

              qDebug() << QPalette()

              FYI The expression "qDebug() << QPalette()" only produces errors.

              Please share those errors.

              I'm surprised there isn't a simple way to set a widget to light or dark mode, even if the colors originate from the system.

              Understand your point. The color scheme is just implemented on a system level by principle. Exceptions are difficult to generalize: what’s the default behavior? If the system scheme changes after having been overridden on a single widget, what should happen with that widget? Ignore the system change? Bounce back to the system scheme? Invert?

              All options are available, they just have to be implemented locally.

              Software Engineer
              The Qt Company, Oslo

              C 1 Reply Last reply
              0
              • Axel SpoerlA Axel Spoerl

                @clarify said in Force light mode on system set to dark mode:

                @Axel-Spoerl said in Force light mode on system set to dark mode:

                qDebug() << QPalette()

                FYI The expression "qDebug() << QPalette()" only produces errors.

                Please share those errors.

                I'm surprised there isn't a simple way to set a widget to light or dark mode, even if the colors originate from the system.

                Understand your point. The color scheme is just implemented on a system level by principle. Exceptions are difficult to generalize: what’s the default behavior? If the system scheme changes after having been overridden on a single widget, what should happen with that widget? Ignore the system change? Bounce back to the system scheme? Invert?

                All options are available, they just have to be implemented locally.

                C Offline
                C Offline
                clarify
                wrote on last edited by clarify
                #7

                @Axel-Spoerl said in Force light mode on system set to dark mode:

                Please share those errors.

                I'm not sure what went wrong before. This time it worked and it printed this:

                QPalette(resolve=0x0,)
                

                Exceptions are difficult to generalize: what’s the default behavior?

                In dark mode, the QTextEdit has a black or near-black background, and text that would have been black is white.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Amineqr
                  wrote on last edited by Amineqr
                  #8

                  In Qt 6.5, a platform-specific option has been introduced to control dark mode behavior (https://doc.qt.io/qt-6/qguiapplication.html#platform-specific-arguments) . We can now customize how the Qt application responds to dark color schemes on the Windows 11 desktop. To enable or disable dark mode, set the environment variable QT_QPA_PLATFORM with the desired value before declaring your QApplication instance.

                  Screenshot 2024-04-08 110753.png

                  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