Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Set button color in QML Qt 6.5
Forum Updated to NodeBB v4.3 + New Features

Set button color in QML Qt 6.5

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 571 Views 1 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.
  • Y Offline
    Y Offline
    Yazid10
    wrote on 26 Jun 2023, 15:45 last edited by
    #1

    Hello everyone,

    I want to set the backgroundcolor of a button in QML. In Qt5, we had something like this :

    Button {        
        text: "Test button"
        palette {
            button: "green"
        }
    }
    

    Does anyone know how to do it in Qt 6.5 ? Thanks in advance

    J M 2 Replies Last reply 26 Jun 2023, 16:15
    0
    • Y Yazid10
      26 Jun 2023, 15:45

      Hello everyone,

      I want to set the backgroundcolor of a button in QML. In Qt5, we had something like this :

      Button {        
          text: "Test button"
          palette {
              button: "green"
          }
      }
      

      Does anyone know how to do it in Qt 6.5 ? Thanks in advance

      J Offline
      J Offline
      JoeCFD
      wrote on 26 Jun 2023, 16:15 last edited by
      #2

      @Yazid10 https://doc.qt.io/qt-6/qml-qtquick-controls-control.html#background-prop

      1 Reply Last reply
      0
      • Y Yazid10
        26 Jun 2023, 15:45

        Hello everyone,

        I want to set the backgroundcolor of a button in QML. In Qt5, we had something like this :

        Button {        
            text: "Test button"
            palette {
                button: "green"
            }
        }
        

        Does anyone know how to do it in Qt 6.5 ? Thanks in advance

        M Offline
        M Offline
        mzimmers
        wrote on 26 Jun 2023, 22:58 last edited by
        #3

        @Yazid10 to amplify on @JoeCFD 's response:

        Button {
            text: "Text Button"
            background: Rectangle {
                anchors.fill: parent
                color: 'green'
            }
        }
        

        BUT:

        If you're running on a Mac or Windows box, you'll get a warning about your current style not supporting customization. To fix this, you need something like the following:

        main.cpp

        #include <QQuickStyle>
        ...
        int main(int argc, char *argv[])
        {
            ...
            QQuickStyle::setStyle("Fusion"); // or whichever you prefer.
            ...
        

        And the use of QQuickStyle will necessitate an addition to your CMakeLists.txt file.

        1 Reply Last reply
        1

        1/3

        26 Jun 2023, 15:45

        • Login

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