Switch QML Type

可打开或关闭的开关按钮。更多

Import Statement: import QtQuick.Controls
Inherits:

AbstractButton

属性

详细说明

开关是一个选项按钮,可以拖动或切换为打开(选中)或关闭(未选中)。开关通常用于在两种状态之间进行选择。对于较大的选项集(如列表中的选项),可考虑使用SwitchDelegate 代替。

Switch 的 API 继承自AbstractButton 。例如,开关的状态可以通过checked 属性来设置。当用户通过触摸、鼠标或键盘交互式点击开关时,将发出clickedAbstractButton::toggled 信号。

ColumnLayout {
    Switch {
        text: qsTr("Wi-Fi")
        checked: Networking.wifiEnabled
        onClicked: Networking.wifiEnabled = checked
    }
    Switch {
        text: qsTr("Bluetooth")
        checked: Networking.bluetoothEnabled
        onClicked: Networking.bluetoothEnabled = checked
    }
}

另请参阅 自定义开关按钮控件

属性文档

position : real [read-only]

该属性保存拇指指示器的逻辑位置。

位置以指示器大小的分数表示,范围为0.0 -1.0 。例如,该位置可用于确定拇指是否已拖过半点。要实现拇指指示器的可视化,应使用从右到左的感知visualPosition

另请参阅 visualPosition


visualPosition : real [read-only]

该属性用于保存拇指指示器的可视化位置。

该位置以指示器大小的一部分表示,范围为0.0 -1.0 。当控件为mirrored 时,该值等于1.0 - position 。因此,考虑到从右到左的支持,该值适用于拇指指示器的可视化。例如,为了确定拇指是否已拖过半点,应使用逻辑position

另请参见 position


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.