Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. OS-independent colour scheme with PySide6

OS-independent colour scheme with PySide6

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 3 Posters 235 Views 3 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.
  • H Offline
    H Offline
    hanspi42
    wrote last edited by hanspi42
    #1

    Dear QT Forum,

    we are a very small university group (most of the time I am alone, sometimes one student assists) who created and maintain an open-source application, https://github.com/hanspi42/signalflowgrapher. The original student team developed it with PyQT5. We recently ported it to PySide6, which observes dark/light mode. The app looks very ugly in Windows dark mode, so we have blocked the dark mode on Windows in the development version. While I am a proficient Python developer, I am unfortuately a QT rookie.

    My first instinct would be to just set the colour palette to be the same on all operating systems. Looking through documentation and forums, I have found many things, like ui Designer, loading palettes from a file, using style sheets, but I could not determine what would be best practice such that it will also be easily maintainable in the future.

    Could anyone tell me the following: my App looks like THIS on Win 11 light mode. I want it to look very similar on all operating systems. How should I proceed?

    THIS:
    sfgrapher.png

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SimonSchroeder
      wrote last edited by
      #2

      The QPalette does not work reliably as still OS specific functions are used for drawing controls which sometimes don't respect the palette. The only thing reliable are stylesheets. However, sometimes setting a stylesheet will slightly change other things as well so that you need to either accept those small changes or try to work against them. One thing that immediately comes to mind is that after setting a style sheet the default buttons of a QDialog don't have the same width anymore.

      It is really hard to come up with a consistent stylesheet. A long time ago we started with the qdarkstylesheet (probably this one https://github.com/ColinDuquesnoy/QDarkStyleSheet), just copying the stylesheet from that repo (because we are using C++). It didn't have a light mode back then. So, we changed the stylesheet so that we can replace the colors with either light colors or dark colors (by replacing every occurence of a color with %1, %2, etc. in the stylesheet, load the stylesheet as QString and provide the correct colors as args). By now, this has a dark and light mode. Using a full stylesheet means that your app looks exactly the same on all platforms.

      I would assume that you can make your app work with a dark mode quite easily. But, I would also expect that your graphing area should also have a light background in dark mode (everything else is usually quite confusing).

      (You could also try to use the Fusion style on all OSes. This might work with a palette because it is a Qt style compared to OS specific styles.)

      H 1 Reply Last reply
      0
      • S SimonSchroeder

        The QPalette does not work reliably as still OS specific functions are used for drawing controls which sometimes don't respect the palette. The only thing reliable are stylesheets. However, sometimes setting a stylesheet will slightly change other things as well so that you need to either accept those small changes or try to work against them. One thing that immediately comes to mind is that after setting a style sheet the default buttons of a QDialog don't have the same width anymore.

        It is really hard to come up with a consistent stylesheet. A long time ago we started with the qdarkstylesheet (probably this one https://github.com/ColinDuquesnoy/QDarkStyleSheet), just copying the stylesheet from that repo (because we are using C++). It didn't have a light mode back then. So, we changed the stylesheet so that we can replace the colors with either light colors or dark colors (by replacing every occurence of a color with %1, %2, etc. in the stylesheet, load the stylesheet as QString and provide the correct colors as args). By now, this has a dark and light mode. Using a full stylesheet means that your app looks exactly the same on all platforms.

        I would assume that you can make your app work with a dark mode quite easily. But, I would also expect that your graphing area should also have a light background in dark mode (everything else is usually quite confusing).

        (You could also try to use the Fusion style on all OSes. This might work with a palette because it is a Qt style compared to OS specific styles.)

        H Offline
        H Offline
        hanspi42
        wrote last edited by hanspi42
        #3

        @SimonSchroeder Thank you very much, that confirms what I thought and feared.

        So I spent a few hours today making our app work with the dark mode. It was easier than I thought, and it looks reasonably nice now in both modes and, on Win 11 at least, even uses the OS's accent colour to highlight stuff.

        Two of my students who looked at it are fine with the dark canvas, as Signal-Flow-Graphs are monochromatic by nature. I do wonder, though, whether I should make the lines thinner in dark mode, right now the white on dark graph looks heavier than the dark on white,

        I have already pushed it to github in case anyone is interested in seeing the code. I guess it is ready for release, pending internal review ^^

        01.png

        02.png

        1 Reply Last reply
        0
        • H hanspi42 has marked this topic as solved
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote last edited by
          #4

          Hi and welcome to devnet,

          On the subject of line thickness, I would say no as for my eyes they already look thinner in dark mode.
          On an other topic, I am wondering whether the red should be a bit darker in the the dark mode. It feels a bit aggressive (again just personal taste)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          H S 2 Replies Last reply
          0
          • SGaistS SGaist

            Hi and welcome to devnet,

            On the subject of line thickness, I would say no as for my eyes they already look thinner in dark mode.
            On an other topic, I am wondering whether the red should be a bit darker in the the dark mode. It feels a bit aggressive (again just personal taste)

            H Offline
            H Offline
            hanspi42
            wrote last edited by
            #5

            @SGaist Thank you, so I'll leave the lines. The red was my choice to try out how different settings look, it actually is the Highlight role, not a fixed colour, in Win 11 that is the Accent colour from the Personalisation>Colours dialogue.

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi and welcome to devnet,

              On the subject of line thickness, I would say no as for my eyes they already look thinner in dark mode.
              On an other topic, I am wondering whether the red should be a bit darker in the the dark mode. It feels a bit aggressive (again just personal taste)

              S Offline
              S Offline
              SimonSchroeder
              wrote last edited by
              #6

              @SGaist said in OS-independent colour scheme with PySide6:

              I am wondering whether the red should be a bit darker in the the dark mode.

              This could certainly help. In the same way, it could help to make the white lines a light gray instead.

              H 1 Reply Last reply
              0
              • S SimonSchroeder

                @SGaist said in OS-independent colour scheme with PySide6:

                I am wondering whether the red should be a bit darker in the the dark mode.

                This could certainly help. In the same way, it could help to make the white lines a light gray instead.

                H Offline
                H Offline
                hanspi42
                wrote last edited by
                #7

                @SimonSchroeder said in OS-independent colour scheme with PySide6:

                @SGaist said in OS-independent colour scheme with PySide6:

                I am wondering whether the red should be a bit darker in the the dark mode.

                This could certainly help. In the same way, it could help to make the white lines a light gray instead.

                I'd love to do that, but there lies my "Qt rookie" problem again, I see many ways but don't know best practice. I have presently used roles everywhere, and the lines have the "text" role which makes them white in Win 11 dark mode. When a light/dark switch happens while the app is open, QT6 does everything for me, except the green background of the "Weight" input field, which signifies a valid SymPy expression. I made that with style sheets, so it updates only when the field redraws. Right after a dark-to-light switch the field will still be a darker green with white text.

                Would the proper way be to do the gray line with style sheets, detect a mode change, and redraw, or can I add roles that then update automatically at light/dark switch? Or should I work with two palettes?

                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