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. Styling a checkbox

Styling a checkbox

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

    Hi
    I want to style a checkbox so it just displays a border, so I followed the example in the documentation

    //           CheckBox {
                    id: checkBox
                    anchors.verticalCenter: parent.verticalCenter
                    visible: model.checkbox
                    style: CheckBoxStyle {
                        indicator: Rectangle {
                            implicitHeight: 16
                            implicitWidth: 16
                            border.color: "red"
                            color: "transparent"
                            Rectangle {
                                visible: control.checked
                                color: "#555"
                                border.color: "#333"
                                radius: 1
                                anchors.margins: 4
                                anchors.fill: parent
                            }
                        }
    
                    }
                }
    

    This does give me a checkbox with a border, however the indicator is now a rectangle within the checkbox, because of the second rectangle definition. Without this definition I cannot 'check' the box, but my requirement is to show a 'tick' when checked (default without styling)
    So I do I style my check box but retain the tick for checked boxes?
    Thanks

    Gojir4G 1 Reply Last reply
    0
    • G GrahamLa

      Hi
      I want to style a checkbox so it just displays a border, so I followed the example in the documentation

      //           CheckBox {
                      id: checkBox
                      anchors.verticalCenter: parent.verticalCenter
                      visible: model.checkbox
                      style: CheckBoxStyle {
                          indicator: Rectangle {
                              implicitHeight: 16
                              implicitWidth: 16
                              border.color: "red"
                              color: "transparent"
                              Rectangle {
                                  visible: control.checked
                                  color: "#555"
                                  border.color: "#333"
                                  radius: 1
                                  anchors.margins: 4
                                  anchors.fill: parent
                              }
                          }
      
                      }
                  }
      

      This does give me a checkbox with a border, however the indicator is now a rectangle within the checkbox, because of the second rectangle definition. Without this definition I cannot 'check' the box, but my requirement is to show a 'tick' when checked (default without styling)
      So I do I style my check box but retain the tick for checked boxes?
      Thanks

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @GrahamLa Hi,

      According to Customizing CheckBox.

      I guess you only need to define background in your style and put then your rectangle with border inside.

      style: CheckBoxStyle {
          background: Rectangle {
              implicitHeight: 16
              implicitWidth: 16
              border.color: "red"
              color: "transparent"
          }
      }
      
      1 Reply Last reply
      1
      • G Offline
        G Offline
        GrahamLa
        wrote on last edited by
        #3

        @Gojir4
        I also need to provide an image for the indicator

                    CheckBox {
                        id: checkBox
                        checked: true
                        anchors.verticalCenter: parent.verticalCenter
                        visible: model.checkbox
                        style: CheckBoxStyle {
                            indicator: Rectangle {
                                implicitHeight: 16
                                implicitWidth: 16
                                border.color: "#22add8"
                                color: "transparent"
                                Image {
                                    x: (parent.width - width) / 2
                                    y: (parent.height - height) / 2
                                    source: "images/tick.png"
                                    visible: checkBox.checked
                                }
                            }
        
                        }
        
        1 Reply Last reply
        0

        • Login

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