Slider QML Type

用于通过沿轨道滑动手柄来选择数值。更多

Import Statement: import QtQuick.Controls
Inherits:

Control

属性

信号

  • moved() (since QtQuick.Controls 2.2 (Qt 5.9))

方法

详细说明

滑块用于通过沿轨道滑动手柄来选择数值。

在下面的示例中,设置了自定义fromvalueto 值:

Slider {
    from: 1
    value: 25
    to: 100
}

position 属性表示为控件大小的一部分,范围为0.0 - 1.0visualPosition 属性与之相同,只是在从右到左的应用中相反。visualPosition 在为滑块设计样式时用于定位手柄。在上面的示例中,在从左到右的应用中,visualPosition 将是0.24 ,而在从右到左的应用中,0.76

有关通过提供两个手柄让用户选择范围的滑块,请参阅RangeSlider

另请参阅 自定义滑块输入控件

属性文档

from : real

该属性用于保存范围的起始值。默认值为0.0

另请参阅 tovalue


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

它通常与implicitContentHeightimplicitBackgroundHeight 一起用于计算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

它通常与implicitContentWidthimplicitBackgroundWidth 一起用于计算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) 中引入。

另请参阅 valuevalueAt() 。


orientation : enumeration

该属性保存方向。

可能的值:

常量说明
Qt.Horizontal水平(默认)
Qt.Vertical垂直

另请参阅 horizontalvertical


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

另请参阅 snapModeincrease() 和decrease()。


to : real

该属性用于保存范围的终值。默认值为1.0

另请参阅 fromvalue


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()

通过stepSize0.1 (如果stepSize 未定义)减小数值。

另请参阅 stepSize


void increase()

增加stepSize0.1 (如果stepSize 未定义)。

另请参阅 stepSize


[since QtQuick.Controls 2.1 (Qt 5.8)] real valueAt(real position)

返回给定position 的值。

该方法在 QtQuick.Controls 2.1 (Qt 5.8) 中引入。

另请参阅 valueposition


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