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. How to set style of button in qml?
Forum Updated to NodeBB v4.3 + New Features

How to set style of button in qml?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 4 Posters 6.6k Views 2 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.
  • P Offline
    P Offline
    Pyroxar
    wrote on last edited by Pyroxar
    #1

    I read the documentation about this but my code not work.
    http://doc.qt.io/qt-5/qml-qtquick-controls-styles-buttonstyle.html

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Controls.Styles 1.4
    import QtQuick.Controls.Material 2.1
    import QtQuick.Layouts 1.0
    import QtQuick.Window 2.2
    import QtQuick.Layouts 1.3
    
    
    ApplicationWindow {
        visible: true
        width: 360
        height: 640
        title: qsTr("Hello World")
    
        Button {
            text: "A button"
            style: ButtonStyle {
                background: Rectangle {
                    implicitWidth: 100
                    implicitHeight: 25
                    border.width: control.activeFocus ? 2 : 1
                    border.color: "#888"
                    radius: 4
                    gradient: Gradient {
                        GradientStop { position: 0 ; color: control.pressed ? "#ccc" : "#eee" }
                        GradientStop { position: 1 ; color: control.pressed ? "#aaa" : "#ccc" }
                    }
                }
            }
        }
    }
    

    I have a error.
    QQmlApplicationEngine failed to load component
    qrc:/main.qml:21 Cannot assign to non-existent property "style"

    What happened?

    1 Reply Last reply
    1
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi! You're importing QtQuick.Controls 2. So your Button is from Controls 2. But styles are only for buttons from Controls 1. See Button QML Type, and Customizing Button for the Controls 2 / Button doc pages.

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

        In my opinion this should be made a lot clearer in the various parts of the documentation...

        sierdzioS 1 Reply Last reply
        1
        • R rowild

          In my opinion this should be made a lot clearer in the various parts of the documentation...

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @rowild said in How to set style of button in qml?:

          In my opinion this should be made a lot clearer in the various parts of the documentation...

          Yeah, it's a very common issue which requires "insider knowledge".

          Thankfully, once Qt 6 comes out, Controls 1 will vanish completely so it will stop being an issue.

          (Z(:^

          1 Reply Last reply
          2

          • Login

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