本页内容

SwitchDelegate QML Type

带开关指示器的项目代理,该指示器可开启或关闭。更多...

Import Statement: import QtQuick.Controls
Inherits:

ItemDelegate

属性

详细说明

SwitchDelegate 提供了一种项目委托,该委托可被切换为开启(选中)或关闭(未选中)状态。SwitchDelegate 通常用于从一组选项中选择一个或多个选项。对于选项集较小的情况,或者需要对选项进行唯一标识的情况,建议改用Switch 。

SwitchDelegate 继承了ItemDelegate 的 API,而 又继承自AbstractButton 。例如,您可以设置text ,并使用AbstractButton API 响应clicks 事件。开关委托的状态可通过checked 属性进行设置。

ListView {
    model: ["Option 1", "Option 2", "Option 3"]
    delegate: SwitchDelegate {
        text: modelData
    }
}

另请参阅 《自定义 SwitchDelegate和Delegate 控件》。

属性文档

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.