本页内容

Switch QML Type

可切换开/关状态的开关按钮。更多...

Import Statement: import QtQuick.Controls
Inherits:

AbstractButton

属性

详细说明

开关是一种单选按钮,可以通过拖动或切换来开启(勾选)或关闭(取消勾选)。开关通常用于在两种状态之间进行选择。对于选项集较大的情况(例如列表中的选项),建议改用SwitchDelegate 。

Switch 控件的 API 继承自AbstractButton 。例如,可通过checked 属性设置开关的状态。当用户通过触摸、鼠标或键盘交互式地点击开关时,会触发clicked 和AbstractButton::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 。

© 2026 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.