如何设置开关大小

How to set Switch size

我想调整Switch的大小(我用QtQuick 1.x2.x都没有关系)。

然而,使用参数 widthheight 不起作用。

有什么想法吗?

您可以 customize the Switch to your needs 通过提供自定义 indicator

默认情况下,这似乎是一个 Item,有两个子节点用于凹槽 (children[0]) 和手柄 (children[1])。由于您无法在创建项目之前访问这些属性,因此您可以使用绑定:

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
    }
}