RangeSlider QML Type
用于通过沿轨道滑动两个手柄来选择数值范围。更多
Import Statement: | import QtQuick.Controls |
Inherits: |
属性
- first
- first.handle : Item
- first.hovered : bool
- first.implicitHandleHeight : real
- first.implicitHandleWidth : real
- first.position : real
- first.pressed : bool
- first.value : real
- first.visualPosition : real
- from : real
- horizontal : bool
(since QtQuick.Controls 2.3 (Qt 5.10))
- live : bool
(since QtQuick.Controls 2.2 (Qt 5.9))
- orientation : enumeration
- second
- second.handle : Item
- second.hovered : bool
- second.implicitHandleHeight : real
- second.implicitHandleWidth : real
- second.position : real
- second.pressed : bool
- second.value : real
- second.visualPosition : real
- snapMode : enumeration
- stepSize : real
- to : real
- touchDragThreshold : real
(since QtQuick.Controls 2.5 (Qt 5.12))
- vertical : bool
(since QtQuick.Controls 2.3 (Qt 5.10))
信号
- void first.moved()
(since QtQuick.Controls 2.5)
- void second.moved()
(since QtQuick.Controls 2.5)
方法
- void first.decrease()
- void first.increase()
- void second.decrease()
- void second.increase()
- void setValues(real firstValue, real secondValue)
- real valueAt(real position)
(since QtQuick.Controls 2.5 (Qt 5.12))
详细说明
RangeSlider 用于通过沿轨道滑动每个手柄来选择由两个值指定的范围。
在下面的示例中,设置了自定义from 和to 值,并设置了first 和second 手柄的初始位置:
RangeSlider { from: 1 to: 100 first.value: 25 second.value: 75 }
要在特定句柄的值发生变化时执行操作,请使用以下语法:
first.onMoved: console.log("first.value changed to " + first.value)
first.position 和second.position 属性以控件大小的分数表示,范围为0.0 - 1.0
。first.visualPosition 和second.visualPosition 属性是相同的,只是在从右到左的应用程序中它们的位置相反。visualPosition
在为 RangeSlider 定型时用于定位手柄。在上面的示例中,在从左到右的应用中,first.visualPosition 将是0.24
,而在从右到左的应用中,0.76
。
有关允许用户选择单个值的滑块,请参阅Slider 。
另请参阅 Qt Quick Controls 中的自定义 RangeSlider、输入控件和焦点管理。
属性文档
属性 | 属性 |
---|---|
值 | 该属性保存from -to 范围内第一个句柄的值。如果from 大于to ,则第一个句柄的值必须大于第二个句柄的值,反之亦然。 默认值为 |
句柄 | 此属性用于保存第一个句柄项。 |
视觉位置 | 该属性用于保存第一个句柄的可视位置。 位置以控件大小的一部分表示,范围为 |
位置 | 该属性用于保存第一个手柄的逻辑位置。 位置以控件大小的一部分表示,范围为 |
按下 | 该属性表示第一个手柄是否被触摸、鼠标或按键按下。 |
悬停 | 此属性显示第一个句柄是否悬停。该属性在QtQuick.Controls 2.1 中引入。 |
隐式手柄宽度 | 该属性用于保存第一个句柄的隐式宽度。该属性在QtQuick.Controls 2.5 中引入。 |
隐式手柄高度 | 该属性用于保存第一个句柄的隐式高度。该属性在QtQuick.Controls 2.5 中引入。 |
另请参阅 first.moved()、first.increase() 和first.decrease()。
from : real |
该属性保存范围的起始值。默认值为0.0
。
另请参阅 to,first.value, 和second.value 。
horizontal : bool |
live : bool |
该属性保留了当拖动各自的手柄时,滑块是否为first.value 和second.value 属性提供实时更新。
默认值为true
。
该属性在 QtQuick.Controls 2.2 (Qt 5.9) 中引入。
另请参阅 first.value 和second.value 。
orientation : enumeration |
属性 | 属性 |
---|---|
值 | 该属性保存第二个句柄在from -to 范围内的值。如果from 大于to ,则第一个句柄的值必须大于第二个句柄的值,反之亦然。 默认值为 |
句柄 | 此属性用于保存第二个句柄项。 |
视觉位置 | 该属性用于保存第二个句柄的可视位置。 位置以控件大小的一部分表示,范围为 |
位置 | 该属性用于保存第二个手柄的逻辑位置。 位置以控件大小的一部分表示,范围为 |
按下 | 该属性表示第二个手柄是否被触摸、鼠标或按键按下。 |
悬停 | 该属性显示第二个句柄是否悬停。该属性在QtQuick.Controls 2.1 中引入。 |
隐式手柄宽度 | 该属性用于保存第二个句柄的隐式宽度。该属性在QtQuick.Controls 2.5 中引入。 |
隐式手柄高度 | 该属性用于保存第二个句柄的隐式高度。该属性在QtQuick.Controls 2.5 中引入。 |
另请参阅 second.moved()、second.increase() 和second.decrease()。
snapMode : enumeration |
stepSize : real |
该属性用于设置步长。默认值为0.0
。
另请参阅 snapMode,first.increase() 和first.decrease() 。
to : real |
该属性用于保存范围的端值。默认值为1.0
。
另请参阅 from,first.value, 和second.value 。
touchDragThreshold : real |
该属性设置了触发触摸拖动事件的阈值(以逻辑像素为单位)。鼠标拖动阈值不受影响。默认值为Application.styleHints.startDragDistance
。
该属性在 QtQuick.Controls 2.5 (Qt 5.12) 中引入。
另请参阅 QStyleHints 。
vertical : bool |
信号文档
|
|
方法文档
使用给定参数设置first.value 和second.value 。
如果to 大于from ,且firstValue 大于secondValue ,则 firstValue 将被箝位为 secondValue。
如果from 大于to ,且 secondValue 大于 firstValue,则 secondValue 将与 firstValue 夹紧。
由于 firstValue 和 secondValue 之间存在循环依赖关系,可能导致分配的值相互箝位,因此可能需要在控制完成后使用此函数设置第一和第二值。
另请参见 stepSize 。
返回给定position 的值。
此方法在 QtQuick.Controls 2.5 (Qt 5.12) 中引入。
另请参阅 first.value,second.value,first.position,second.position 和live 。
© 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.