Search code examples
qtswitch-statementqmlqtquick2qt-quick

How to set Switch size


I would like to resize a Switch (It doesn't matter if I use aQtQuick 1.x or 2.x).

How ever, using parameters width and height doesn't work.

Any idea ?


Solution

  • You can customize the Switch to your needs by providing a custom indicator.

    By default this seems to be an Item with two children for the groove (children[0]) and the handle (children[1]). As you can't access those properties before the item is created, you could use a binding:

    Switch {
        id: swch
        anchors.fill: parent
    
        Binding {
            target: swch.indicator
            property: 'width'
            value: swch.width
        }
    
        Binding {
            target: (swch.indicator ? swch.indicator.children[0] : null)
            property: 'width'
            value: swch.width
        }
    }