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. How to get this style on a button
Forum Update on Monday, May 27th 2025

How to get this style on a button

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstyleqstylesheetfusion
10 Posts 4 Posters 2.2k Views
  • 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 10 Nov 2021, 12:03 last edited by
    #1

    Hey

    I'm trying to wrap my head around how Qt does Fusion style, but do it via css so I can edit certain parts of it >
    b4e22fa8-de0e-4e07-8255-3c961c3d3ac8-image.png
    Does any1 have any idea?
    It has like doble outline, darker & lighter & some grad over it.
    I'm stuck.
    Half of the CSS code I feed to qt does not work.
    Are there any plans to modernize CSS & get it up to latest ver ?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      LRDPRDX
      wrote on 10 Nov 2021, 12:20 last edited by
      #2

      This may help (regarding colors):

          QColor darkGray(53, 53, 53);
          QColor gray(128, 128, 128);
          QColor black(25, 25, 25);
          QColor blue(42, 130, 218);
      
          QPalette darkPalette;
          darkPalette.setColor(QPalette::Window, darkGray);
          darkPalette.setColor(QPalette::WindowText, Qt::white);
          darkPalette.setColor(QPalette::Base, black);
          darkPalette.setColor(QPalette::AlternateBase, darkGray);
          darkPalette.setColor(QPalette::ToolTipBase, blue);
          darkPalette.setColor(QPalette::ToolTipText, Qt::white);
          darkPalette.setColor(QPalette::Text, Qt::white);
          darkPalette.setColor(QPalette::Button, darkGray);
          darkPalette.setColor(QPalette::ButtonText, Qt::white);
          darkPalette.setColor(QPalette::Link, blue);
          darkPalette.setColor(QPalette::Highlight, blue);
          darkPalette.setColor(QPalette::HighlightedText, Qt::black);
      
          darkPalette.setColor(QPalette::Active, QPalette::Button, gray.darker());
          darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray);
          darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray);
          darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray);
          darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray);
      

      Original link

      1 Reply Last reply
      1
      • L Offline
        L Offline
        LRDPRDX
        wrote on 10 Nov 2021, 12:28 last edited by
        #3

        Also here the Combinear qss looks similar so you can download this qss and edit it.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          LRDPRDX
          wrote on 10 Nov 2021, 12:35 last edited by
          #4

          BTW, here is how I used the above palette :

          screenshot_11_10_19:32:26.png

          To change the active text color I use this function (ofc could be lambda) :

          inline void ColorButton( QPushButton* button, QColor color )
          {
              QPalette palette = button->palette();
              palette.setColor( QPalette::Active, QPalette::ButtonText, color );
              button->setPalette( palette );
              button->update();
          }
          
          D 1 Reply Last reply 10 Nov 2021, 12:53
          0
          • L LRDPRDX
            10 Nov 2021, 12:35

            BTW, here is how I used the above palette :

            screenshot_11_10_19:32:26.png

            To change the active text color I use this function (ofc could be lambda) :

            inline void ColorButton( QPushButton* button, QColor color )
            {
                QPalette palette = button->palette();
                palette.setColor( QPalette::Active, QPalette::ButtonText, color );
                button->setPalette( palette );
                button->update();
            }
            
            D Offline
            D Offline
            Dariusz
            wrote on 10 Nov 2021, 12:53 last edited by
            #5

            @LRDPRDX Hey
            Yes I'm using pallete too, but if I want to increase/decrease padding... then I lose style. So I have to remake the style in css. Its a bummer we cant just... "change 1 property" of a style without it going bananas.

            J 1 Reply Last reply 11 Nov 2021, 01:54
            0
            • D Dariusz
              10 Nov 2021, 12:53

              @LRDPRDX Hey
              Yes I'm using pallete too, but if I want to increase/decrease padding... then I lose style. So I have to remake the style in css. Its a bummer we cant just... "change 1 property" of a style without it going bananas.

              J Offline
              J Offline
              JKSH
              Moderators
              wrote on 11 Nov 2021, 01:54 last edited by
              #6

              @Dariusz said in How to get this style on a button:

              if I want to increase/decrease padding... then I lose style

              As a workaround, call QWidget::setMinimumSize() on your buttons. Increasing the minimum size has a similar effect as increasing padding.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              D 1 Reply Last reply 11 Nov 2021, 17:58
              0
              • J JKSH
                11 Nov 2021, 01:54

                @Dariusz said in How to get this style on a button:

                if I want to increase/decrease padding... then I lose style

                As a workaround, call QWidget::setMinimumSize() on your buttons. Increasing the minimum size has a similar effect as increasing padding.

                D Offline
                D Offline
                Dariusz
                wrote on 11 Nov 2021, 17:58 last edited by
                #7

                @JKSH AH yes, could do... but I'm trying to css entire app with hundreds of buttons/etc..
                CSS is really great "idea" to do it, just a bit of a problem with Qt as qt does not respect half of the css I give it from web searches & breaks with fusion :- (

                Will qt update CSS support to be more... modern ?

                Or is CSS no longer the way to go, in which case what is?

                J L 2 Replies Last reply 12 Nov 2021, 03:16
                0
                • C Online
                  C Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 11 Nov 2021, 18:17 last edited by
                  #8

                  @Dariusz said in How to get this style on a button:

                  it of a problem with Qt as qt does not respect half of the css I give it from web searches & breaks with fusion :- (

                  Because it's not CSS but QSS.

                  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
                  1
                  • D Dariusz
                    11 Nov 2021, 17:58

                    @JKSH AH yes, could do... but I'm trying to css entire app with hundreds of buttons/etc..
                    CSS is really great "idea" to do it, just a bit of a problem with Qt as qt does not respect half of the css I give it from web searches & breaks with fusion :- (

                    Will qt update CSS support to be more... modern ?

                    Or is CSS no longer the way to go, in which case what is?

                    J Offline
                    J Offline
                    JKSH
                    Moderators
                    wrote on 12 Nov 2021, 03:16 last edited by
                    #9

                    @Dariusz said in How to get this style on a button:

                    CSS is really great "idea" to do it, just a bit of a problem with Qt as qt does not respect half of the css I give it from web searches & breaks with fusion :- (

                    As @Christian-Ehrlicher said, Qt style sheets are inspired by CSS, but it is not CSS. Here is the list of the CSS 2.1 properties (plus custom Qt-specific properties) supported by Qt style sheets: https://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties

                    What you get from web searches is mostly for CSS 3. This is designed for websites and web apps, not for desktop widgets.

                    Will qt update CSS support to be more... modern ?

                    Not for widgets.

                    CSS support is complex, and essentially requires a heavyweight web engine.

                    Or is CSS no longer the way to go, in which case what is?

                    There are a few options:

                    • Stay with widgets and use stylesheets by following https://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties
                    • Stay with widgets and style your GUI programmatically using the C++ API (e.g. setMinimumSize(), setMargins(), etc.)
                    • Switch to Qt Quick and use QML styling:
                      • https://doc.qt.io/qt-6/qtquickcontrols2-styles.html
                      • https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#creating-a-custom-style
                    • Write a HTML5 + CSS3 + JS app and run it via Qt WebEngine

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply
                    2
                    • D Dariusz
                      11 Nov 2021, 17:58

                      @JKSH AH yes, could do... but I'm trying to css entire app with hundreds of buttons/etc..
                      CSS is really great "idea" to do it, just a bit of a problem with Qt as qt does not respect half of the css I give it from web searches & breaks with fusion :- (

                      Will qt update CSS support to be more... modern ?

                      Or is CSS no longer the way to go, in which case what is?

                      L Offline
                      L Offline
                      LRDPRDX
                      wrote on 13 Nov 2021, 13:54 last edited by
                      #10

                      @Dariusz said in How to get this style on a button:

                      @JKSH AH yes, could do... but I'm trying to css entire app with hundreds of buttons/etc..

                      I think you could inherit from the QPushButton then:

                      class MyButton : public QPushButton
                      {
                          MyButton( ... ) :
                              ...
                          {
                              setMinimumSize( ... );
                          }
                      };
                      1 Reply Last reply
                      0

                      2/10

                      10 Nov 2021, 12:20

                      8 unread
                      • Login

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