Slider QML Type
用于通过沿轨道滑动手柄来选择数值。更多
| Import Statement: | import QtQuick.Controls |
| Inherits: |
属性
- from : real
- handle : Item
- horizontal : bool
(since QtQuick.Controls 2.3 (Qt 5.10)) - implicitHandleHeight : real
(since QtQuick.Controls 2.5 (Qt 5.12)) - implicitHandleWidth : real
(since QtQuick.Controls 2.5 (Qt 5.12)) - live : bool
(since QtQuick.Controls 2.2 (Qt 5.9)) - orientation : enumeration
- position : real
- pressed : bool
- snapMode : enumeration
- stepSize : real
- to : real
- touchDragThreshold : real
(since QtQuick.Controls 2.5 (Qt 5.12)) - value : real
- vertical : bool
(since QtQuick.Controls 2.3 (Qt 5.10)) - visualPosition : real
信号
- moved()
(since QtQuick.Controls 2.2 (Qt 5.9))
方法
详细说明
滑块用于通过沿轨道滑动手柄来选择数值。
在下面的示例中,设置了自定义from 、value 和to 值:
Slider { from: 1 value: 25 to: 100 }
position 属性表示为控件大小的一部分,范围为0.0 - 1.0 。visualPosition 属性与之相同,只是在从右到左的应用中相反。visualPosition 在为滑块设计样式时用于定位手柄。在上面的示例中,在从左到右的应用中,visualPosition 将是0.24 ,而在从右到左的应用中,0.76 。
有关通过提供两个手柄让用户选择范围的滑块,请参阅RangeSlider 。
属性文档
from : real
该属性保存范围的起始值。默认值为0.0 。
handle : Item
此属性包含句柄项。
另请参阅 自定义滑块。
horizontal : bool [read-only, since QtQuick.Controls 2.3 (Qt 5.10)]
该属性表示滑块是否水平。
该属性在 QtQuick.Controls 2.3 (Qt 5.10) 中引入。
另请参阅 orientation 。
implicitHandleHeight : real [read-only, since QtQuick.Controls 2.5 (Qt 5.12)]
该属性包含隐式句柄高度。
其值等于handle ? handle.implicitHeight : 0 。
它通常与implicitContentHeight 和implicitBackgroundHeight 一起用于计算implicitHeight 。
该属性在 QtQuick.Controls 2.5 (Qt 5.12) 中引入。
另请参阅 implicitHandleWidth 。
implicitHandleWidth : real [read-only, since QtQuick.Controls 2.5 (Qt 5.12)]
该属性用于保存隐式句柄宽度。
其值等于handle ? handle.implicitWidth : 0 。
它通常与implicitContentWidth 和implicitBackgroundWidth 一起用于计算implicitWidth 。
该属性在 QtQuick.Controls 2.5 (Qt 5.12) 中引入。
另请参阅 implicitHandleHeight 。
live : bool [since QtQuick.Controls 2.2 (Qt 5.9)]
该属性用于设置滑块在拖动手柄时是否为value 属性提供实时更新。
默认值为true 。
该属性在 QtQuick.Controls 2.2 (Qt 5.9) 中引入。
orientation : enumeration
此属性表示方向。
可能的值
| 常量 | 说明 |
|---|---|
Qt.Horizontal | 水平(默认) |
Qt.Vertical | 垂直 |
另请参阅 horizontal 和vertical 。
position : real [read-only]
该属性用于保存句柄的逻辑位置。
位置表示为控件大小的一部分,范围为0.0 - 1.0 。为使滑块可视化,应使用从右到左的感知visualPosition 。
另请参阅 value,visualPosition, 和valueAt() 。
pressed : bool
此属性表示滑块是通过触摸、鼠标还是按键按下的。
snapMode : enumeration
该属性用于保存抓取模式。
捕捉模式决定了滑块手柄在stepSize 上的行为方式。
可能的值
| 常量 | 说明 |
|---|---|
Slider.NoSnap | 滑块不抓取(默认)。 |
Slider.SnapAlways | 滑块在拖动手柄时卡住。 |
Slider.SnapOnRelease | 滑块在被拖动时不会咬合,只有在释放手柄后才会咬合。 |
下表用动画演示了各种模式。在每个动画中,鼠标光标和stepSize (0.2) 的移动都是相同的。
| 数值 | 示例 |
Slider.NoSnap | |
Slider.SnapAlways | |
Slider.SnapOnRelease |
另请参阅 stepSize 。
stepSize : real
该属性表示步长。默认值为0.0 。
另请参阅 snapMode,increase() 和decrease() 。
to : real
该属性用于保存范围的终值。默认值为1.0 。
touchDragThreshold : real [since QtQuick.Controls 2.5 (Qt 5.12)]
该属性用于保存触发触摸拖动事件的阈值(以逻辑像素为单位)。鼠标拖动阈值不受影响。默认值是Application.styleHints.startDragDistance 。
此属性在 QtQuick.Controls 2.5 (Qt 5.12) 中引入。
另请参阅 QStyleHints 。
value : real
该属性的值范围为from -to 。默认值为0.0 。
另请参阅 position 。
vertical : bool [read-only, since QtQuick.Controls 2.3 (Qt 5.10)]
该属性表示滑块是否垂直。
该属性在 QtQuick.Controls 2.3 (Qt 5.10) 中引入。
另请参阅 orientation 。
visualPosition : real [read-only]
该属性用于保存句柄的可视化位置。
位置以控件大小的一部分表示,范围为0.0 - 1.0 。当控件为mirrored 时,该值等于1.0 - position 。因此,考虑到从右向左的支持,该值适合可视化滑块。
另请参见 position 。
信号文档
[since QtQuick.Controls 2.2 (Qt 5.9)] moved()
当用户通过触摸、鼠标、滚轮或按键交互式移动滑块时,就会发出该信号。
注: 相应的处理程序是onMoved 。
此信号在 QtQuick.Controls 2.2 (Qt 5.9) 中引入。
方法文档
void decrease()
通过stepSize 或0.1 (如果stepSize 未定义)减小数值。
另请参阅 stepSize 。
void increase()
通过stepSize 或0.1 (如果stepSize 未定义)增加数值。
另请参阅 stepSize 。
[since QtQuick.Controls 2.1 (Qt 5.8)] real valueAt(real position)
返回给定position 的值。
该方法在 QtQuick.Controls 2.1 (Qt 5.8) 中引入。
© 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.