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 861 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.
  • JonBJ JonB

    @Chris-Kawa said in partially update default stylesheet:

    if platform style allows it, Qt can apply the qss style to just some elements without completely replacing the style, but that is not the case for border (often text color and such, but it differs on different platforms and is not portable).

    Yes, but I never know which things can be changed without losing native styling and which cannot.

    Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote last edited by
    #15

    @JonB said in partially update default stylesheet:

    Yes, but I never know which things can be changed without losing native styling and which cannot.

    Because this depends on the underlying style which defines what can be changed and what not without breaking the rest.

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

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @JonB said in partially update default stylesheet:

      Yes, but I never know which things can be changed without losing native styling and which cannot.

      Because this depends on the underlying style which defines what can be changed and what not without breaking the rest.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote last edited by
      #16

      @Christian-Ehrlicher
      I understand that, but as a dev I don't know which they are and which not. Just saying. At least that explains why sometimes you can make a change without breaking windowing style and sometimes you lose it.

      Christian EhrlicherC 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        @tech032142 The widget uses your default platform style, which often draws the border and background with some OS provided images or brushes. When you call setStyleSheet you're changing the style of your widget to Qt's StylesheetStyle, so you're no longer using the platform style on any parts of the widget. In some cases, if platform style allows it, Qt can apply the qss style to just some elements without completely replacing the style, but that is not the case for border (often text color and such, but it differs on different platforms and is not portable).

        T Offline
        T Offline
        tech032142
        wrote last edited by
        #17

        @Chris-Kawa It makes more sense now, i couldn't find this in the docs maybe I missed it ?

        1 Reply Last reply
        0
        • JonBJ JonB

          @Christian-Ehrlicher
          I understand that, but as a dev I don't know which they are and which not. Just saying. At least that explains why sometimes you can make a change without breaking windowing style and sometimes you lose it.

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote last edited by
          #18

          @JonB said in partially update default stylesheet:

          At least that explains why sometimes you can make a change without breaking windowing style and sometimes you lose it.

          Correct - it sometimes depends even on the underlying style.

          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
          • T tech032142

            I am on macOS Sonoma with Qt 6.9.3,

            the first image is untouched no setStyleSheet calls, the other one is after setting styles

            My question is :
            setStyleSheet resets all style rules how do I preserve everything and just change the border color ?

            I also tried

            "QGroupBox { border : 2px solid #CCCCCC}"

            I am extending QGroupBox in that class by the way

            New Project.jpg

            S Offline
            S Offline
            SimonSchroeder
            wrote last edited by
            #19

            @tech032142 said in partially update default stylesheet:

            how do I preserve everything and just change the border color ?

            This is general problem with stylesheets: You don't.

            My personal experience (where it is most obvious) is the following: On Windows, by default, the "Ok" and "Cancel" buttons in a dialog have the same width. However, once you apply any stylesheet the "Ok" buttons is smaller than the "Cancel" button because the text is shorter. Applying any stylesheet at all will mess with several aspects of layouts and designs. Still, there is no better general options than to use stylesheets.

            @JonB said in partially update default stylesheet:

            Yes, but I never know which things can be changed without losing native styling and which cannot.

            In a perfect world we could just adapt the palette instead of setting a stylesheet (at least for color). It's not gonna happen.

            JonBJ 1 Reply Last reply
            0
            • S SimonSchroeder

              @tech032142 said in partially update default stylesheet:

              how do I preserve everything and just change the border color ?

              This is general problem with stylesheets: You don't.

              My personal experience (where it is most obvious) is the following: On Windows, by default, the "Ok" and "Cancel" buttons in a dialog have the same width. However, once you apply any stylesheet the "Ok" buttons is smaller than the "Cancel" button because the text is shorter. Applying any stylesheet at all will mess with several aspects of layouts and designs. Still, there is no better general options than to use stylesheets.

              @JonB said in partially update default stylesheet:

              Yes, but I never know which things can be changed without losing native styling and which cannot.

              In a perfect world we could just adapt the palette instead of setting a stylesheet (at least for color). It's not gonna happen.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote last edited by
              #20

              @SimonSchroeder
              I come from an HTML/CSS background. And therefore web pages/elements, not native windowing system ones. In the former I have no trouble adjusting any individual element style attribute, and if I need to I can read back existing attribute values e.g. from JavaScript. I realise this is not the same for Qt/QSS, which is trying to do some CSS against non-CSS-HTML windowing widgets, but that is where it gets "complicated/disappointing" to my experience/expectations.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote 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 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 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 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 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 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