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. partially update default stylesheet
Forum Updated to NodeBB v4.3 + New Features

partially update default stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
26 Posts 6 Posters 2.4k Views 4 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #21

    Hi,

    Another option is to create a QProxyStyle to do the painting you want.

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

    S 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      Another option is to create a QProxyStyle to do the painting you want.

      S Offline
      S Offline
      SimonSchroeder
      wrote on last edited by
      #22

      @SGaist said in partially update default stylesheet:

      Another option is to create a QProxyStyle to do the painting you want.

      I consider this quite complicated. And sometimes I just want the native look and just change a single thing (like the OP). I don't think it is reasonable that everybody reimplements the native look with a QProxyStyle. It would be more helpful if it was provided by Qt directly. At least with QtWidget I would rather be able to just set the palette to switch between light mode and dark mode and not write stylesheets for that.

      Chris KawaC 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #23

        There's no need to reimplement the whole style in the QProxyStyle. Just the things that you actually want to be modified.
        See this nice article from KDAB on the matter.

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

        S 1 Reply Last reply
        0
        • S SimonSchroeder

          @SGaist said in partially update default stylesheet:

          Another option is to create a QProxyStyle to do the painting you want.

          I consider this quite complicated. And sometimes I just want the native look and just change a single thing (like the OP). I don't think it is reasonable that everybody reimplements the native look with a QProxyStyle. It would be more helpful if it was provided by Qt directly. At least with QtWidget I would rather be able to just set the palette to switch between light mode and dark mode and not write stylesheets for that.

          Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #24

          @SimonSchroeder The problem is that "native style" means it uses native OS facilities to paint the control. Sometimes there's some level of customization provided by those, but more often than not there's none.

          Take a widget background as an example - a Windows native style uses a call to DrawThemeBackgroundEx (among others). It just gives the OS a region and gets a painted image back. There's some degree of customization, e.g. you can pass a flag to omit a frame, but Qt code doesn't know what is drawn - a gradient, rounded corners, how thick the frame is etc.
          The same executable with the same native style plugin will get something different on Windows Vista, 8, 10 or 11. That being said Qt can't "just let you change one thing". It gets all the things as a single bitmap, so you either take it or recreate the whole thing as a custom style (qss). Qt can't do it for you because it's dynamic and depends on the OS. If you decide to do it you take responsibility for it not looking native anymore. Trying to recreate native look with qss is futile, because native look can change at any given OS update.

          1 Reply Last reply
          2
          • SGaistS SGaist

            There's no need to reimplement the whole style in the QProxyStyle. Just the things that you actually want to be modified.
            See this nice article from KDAB on the matter.

            S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #25

            @SGaist said in partially update default stylesheet:

            There's no need to reimplement the whole style in the QProxyStyle. Just the things that you actually want to be modified.
            See this nice article from KDAB on the matter.

            I didn't know about the article. However, I'm not entirely sure if the statement "Just the things that you actually want to be modified" is correct. It seems as if the article assumes that you don't want to use a native style anyway because the style should look the same on all platforms. Correct me if I'm wrong, but if I am using the Windows native style and I just want to change the border color of a QPushButton in my own QStyle-derived class, I only can try to change a single thing if I'm calling the QPushButton paint method of the underlying style. This actually does not change anything. Instead, I need to draw my own button entirely to apply the changes because the native Windows style does not respect my wishes.

            Or I am wrong about this and there is actually some code that copies the native style (contrary to what @Chris-Kawa said). Then the big question is why I can't just change this by setting the QPalette instead...

            SGaistS 1 Reply Last reply
            0
            • S SimonSchroeder

              @SGaist said in partially update default stylesheet:

              There's no need to reimplement the whole style in the QProxyStyle. Just the things that you actually want to be modified.
              See this nice article from KDAB on the matter.

              I didn't know about the article. However, I'm not entirely sure if the statement "Just the things that you actually want to be modified" is correct. It seems as if the article assumes that you don't want to use a native style anyway because the style should look the same on all platforms. Correct me if I'm wrong, but if I am using the Windows native style and I just want to change the border color of a QPushButton in my own QStyle-derived class, I only can try to change a single thing if I'm calling the QPushButton paint method of the underlying style. This actually does not change anything. Instead, I need to draw my own button entirely to apply the changes because the native Windows style does not respect my wishes.

              Or I am wrong about this and there is actually some code that copies the native style (contrary to what @Chris-Kawa said). Then the big question is why I can't just change this by setting the QPalette instead...

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #26

              @SimonSchroeder Native styles are implemented such that they follow the original platform style and are thus free to ignore modified palette values to stay coherent.

              Thus, depending on what you want to change, you will need to check what the original style does underneath. I am not claiming that it's simple for everything, far from it.

              Many times, it's a question of re-implementing drawPrimitive to either call the base class implementation with modified values or having your own implementation based out of the original class.

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

              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