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. [solved]Button: checkable and checked not working

[solved]Button: checkable and checked not working

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.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.
  • Q Offline
    Q Offline
    qmlLearner
    wrote on last edited by
    #1

    Hi experts!

    I recently started learning qml and I am now playing with the controls a bit.
    My goal is to have a checkable button. However, the property checkable doesn't seem to have any influence on the button: The button does not remain pressed. Also, if setting checked to true, the button is not in the pressed state.
    code snippet:
    @
    import QtQuick 2.0
    import QtQuick.Controls 1.0

    Rectangle {
    width: 360
    height: 360
    Text {
    text: qsTr("Hello World")
    anchors.centerIn: parent
    }
    MouseArea {
    anchors.fill: parent
    onClicked: {
    Qt.quit();
    }
    }
    Button{
    text: "asdfs"
    checkable: true
    checked: true
    }
    }
    @

    some infos:

    • using qt5.1.1
    • tried it in window and ubuntu
    • tried "Button" as well as "ToolButton"

    Did I miss something? Do you have some ideas why it is not working as intended? Thank you for any help! :)

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      I guess the button state gets change to pressed but is not seen on the button widget as it should be by default like the QPushbutton.
      Applying the stylesheet make it work though,
      @
      Button{
      text: "asdfs"
      checkable: true
      checked: true
      style: ButtonStyle {
      background: Rectangle {
      border.width: control.activeFocus ? 2 : 1
      border.color: "#888"
      radius: 4
      color: control.checked ? "#ccc" : "#eee"
      }
      }
      }
      @

      157

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qmlLearner
        wrote on last edited by
        #3

        Thank you very much for the quick reply!
        The stylesheet does the trick :)
        Fortunately, in qt5.2, it works out of the box...

        1 Reply Last reply
        0
        • MarkkyboyM Markkyboy referenced this topic on

        • Login

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