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. QPushButton default windows style sheet
Forum Updated to NodeBB v4.3 + New Features

QPushButton default windows style sheet

Scheduled Pinned Locked Moved Solved General and Desktop
qpushbutton stystylesheetwindows
12 Posts 5 Posters 9.9k 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.
  • R Offline
    R Offline
    RonenB
    wrote on last edited by
    #1

    Hello,
    All I want to do is to change the default windows QPushButton color from blue to green, saving all other style parameters intact. I looked everywhere for the default parameters with no success. Calling styleSheet() returns empty string.

    Thanks,
    Ronen

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome
      Sadly Its not possible to get a default style sheet from a Widget.
      Its using a QStyle which is not a style sheet. So it will return empty string as you seen

      When using a Style Sheets, its all or nothing. So Often one has to specify extra settings to get
      the exact look wanted.

      1 Reply Last reply
      1
      • R Offline
        R Offline
        RonenB
        wrote on last edited by
        #3

        @mrjj tnx for the warm welcome.
        The default is QWindowsStyle but there isn't an access to the button's color.
        QWindowsStylePrivate is not guarantied so I can't count on using it with QWindowsStyle protected constructor.
        I thought maybe I could use the palette but it doesn't work.
        It's so frustrating that I can't change only part of the parameters and even if I want to create a new style sheet I can't find what are the default parameters to hard code them.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Colors of a button are style dependent as already stated. And when I say style I don't mean QStyle (although that's how it is exposed in Qt), I mean OS style eg. Luna on XP, Aero on Vista/7 or some other styles of window managers elsewhere. Some styles on some platforms use fancy visual effects, gradients, glows, animations etc. You can't get a default color because there simply might not be any single color to give to you.

          Stylesheets are a totally different beasts. The default native drawing doesn't use stylesheets. They are a way to override native style dependent painting with HTML-like drawing. Usually if you change one of the basic style elements like border or background Qt disables native painting entirely and falls back to a simple HTML box model. So in short you can't change just one property of a stylesheet and keep original native style painting. There are exceptions to that (e.g. changing text color), but that's what they are - exceptions. In general it's either stylesheets or native painting. Mixing is generally not possible and even if it has the desired result with one theme it might not with another.

          Palette is yet another thing. Most platforms define some sort of palette that a user can adjust and that transfers to Qt's QPalette. But nowadays most platforms divert from the idea of letting you control every single aspect of ui look and instead offer you simple things like "theme color". For Qt this means that changing a palette is usually a bad idea and the results will vary from user to user. Some styles ignore palette colors and apply their fancy themed drawing like gradients and such. Some styles will ignore one subset of a palette, some will ignore another. It's generally a minefield to try and control colors with palettes consistently. I advise against that.

          1 Reply Last reply
          1
          • R Offline
            R Offline
            RonenB
            wrote on last edited by
            #5

            Tnx Moderato for elaborating. Is there a reference which holds the attributes of the different default styles (Windows, Mac etc.) ? It will save me from trying to mimic every attribute by myself.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Is there a reference which holds the attributes of the different default styles (Windows, Mac etc.) ?

              Attributes of what? If you mean stylesheet values then it's mostly not possible to mimic native look with it.
              Widgets in native styles are not drawn with stylesheets. They use native methods wrapped in QStyle::drawControl and friends, which delegate the drawing to the OS via platform plugin.

              R 1 Reply Last reply
              1
              • Chris KawaC Chris Kawa

                Is there a reference which holds the attributes of the different default styles (Windows, Mac etc.) ?

                Attributes of what? If you mean stylesheet values then it's mostly not possible to mimic native look with it.
                Widgets in native styles are not drawn with stylesheets. They use native methods wrapped in QStyle::drawControl and friends, which delegate the drawing to the OS via platform plugin.

                R Offline
                R Offline
                RonenB
                wrote on last edited by
                #7

                I'm trying to figure if QProxyStyle can be of any use. Is it a good option for changing single style values?

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  It depends on which elements you want to change. The point is that there is no good way to change single elements (by element I mean parts of a single control).

                  The only thing I found you can change pretty reliable is text color. Most other stuff is highly platform/style dependent. For example platform plugin usually gets a button from OS as a bitmap of some sort. There's usually no OS provided API, let alone exposed by Qt, to get access to sub-elements like bevels, gradient components etc.

                  I might be exaggerating a little, but It's mostly all or nothing deal.

                  R 1 Reply Last reply
                  1
                  • Chris KawaC Chris Kawa

                    It depends on which elements you want to change. The point is that there is no good way to change single elements (by element I mean parts of a single control).

                    The only thing I found you can change pretty reliable is text color. Most other stuff is highly platform/style dependent. For example platform plugin usually gets a button from OS as a bitmap of some sort. There's usually no OS provided API, let alone exposed by Qt, to get access to sub-elements like bevels, gradient components etc.

                    I might be exaggerating a little, but It's mostly all or nothing deal.

                    R Offline
                    R Offline
                    RonenB
                    wrote on last edited by
                    #9

                    @Chris-Kawa that's what I eventually figured :(
                    Thanks a lot for your help and great explanations!

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      KY4CT
                      wrote on last edited by
                      #10

                      @Chris-Kawa Sorry for bringing up the really old thread, but a quick question I have is simple, after using a stylesheet is there not a way to get the control to revert to os-dependant rendering?

                      JonBJ 1 Reply Last reply
                      0
                      • K KY4CT

                        @Chris-Kawa Sorry for bringing up the really old thread, but a quick question I have is simple, after using a stylesheet is there not a way to get the control to revert to os-dependant rendering?

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #11

                        @KY4CT
                        My understanding (stand to be corrected) is that if you supply stylesheet rules for a widget type (might depend on widget or what you set in the sheet, not sure) that replaces the OS/theme and you no longer get that. Don't supply such a rule if you want the original appearance.

                        1 Reply Last reply
                        0
                        • Chris KawaC Offline
                          Chris KawaC Offline
                          Chris Kawa
                          Lifetime Qt Champion
                          wrote on last edited by Chris Kawa
                          #12

                          To remove stylesheet style simply set an empty string i.e.

                          someWidget->setStyleSheet("border: 1px solid red; background-color: blue;"); // sets a stylesheet
                          someWidget->setStyleSheet({});  // removes a stylesheet
                          
                          1 Reply Last reply
                          1

                          • Login

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