Slider QML Type

Used to select a value by sliding a handle along a track. More...

Import Statement: import QtQuick.Controls 2.1
Since: Qt 5.7
Inherits:

Control

Properties

Methods

Detailed Description

Slider is used to select a value by sliding a handle along a track.

In the example below, custom from, value, and to values are set:

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

The position property is expressed as a fraction of the control's size, in the range 0.0 - 1.0. The visualPosition property is the same, except that it is reversed in a right-to-left application. The visualPosition is useful for positioning the handle when styling Slider. In the example above, visualPosition will be 0.24 in a left-to-right application, and 0.76 in a right-to-left application.

See also Customizing Slider and Input Controls.

Property Documentation

from : real

This property holds the starting value for the range. The default value is 0.0.

See also to and value.


handle : Item

This property holds the handle item.

See also Customizing Slider.


orientation : enumeration

This property holds the orientation.

Possible values:

ConstantDescription
Qt.HorizontalHorizontal (default)
Qt.VerticalVertical

[read-only] position : real

This property holds the logical position of the handle.

The position is expressed as a fraction of the control's size, in the range 0.0 - 1.0. Unlike the value property, the position is continuously updated while the handle is dragged. For visualizing a slider, the right-to-left aware visualPosition should be used instead.

See also value, visualPosition, and valueAt().


pressed : bool

This property holds whether the slider is pressed.


snapMode : enumeration

This property holds the snap mode.

Possible values:

ConstantDescription
Slider.NoSnapThe slider does not snap (default).
Slider.SnapAlwaysThe slider snaps while the handle is dragged.
Slider.SnapOnReleaseThe slider does not snap while being dragged, but only after the handle is released.

In the following table, the various modes are illustrated with animations. The movement of the mouse cursor and the stepSize (0.2) are identical in each animation.

ValueExample
Slider.NoSnap

Slider.SnapAlways

Slider.SnapOnRelease

See also stepSize.


stepSize : real

This property holds the step size. The default value is 0.0.

See also snapMode, increase(), and decrease().


to : real

This property holds the end value for the range. The default value is 1.0.

See also from and value.


value : real

This property holds the value in the range from - to. The default value is 0.0.

Unlike the position property, the value is not updated while the handle is dragged, but only after the value has been chosen and the slider has been released. The valueAt() method can be used to get continuous updates.

See also position and valueAt().


[read-only] visualPosition : real

This property holds the visual position of the handle.

The position is expressed as a fraction of the control's size, in the range 0.0 - 1.0. When the control is mirrored, the value is equal to 1.0 - position. This makes the value suitable for visualizing the slider, taking right-to-left support into account.

See also position.


Method Documentation

void decrease()

Decreases the value by stepSize or 0.1 if stepSize is not defined.

See also stepSize.


void increase()

Increases the value by stepSize or 0.1 if stepSize is not defined.

See also stepSize.


real valueAt(real position)

Returns the value for the given position.

The value property is not updated while the handle is dragged, but this method can be used to get continuous value updates:

Slider {
    id: slider
    value: 0.5

    ToolTip {
        parent: slider.handle
        visible: slider.pressed
        text: slider.valueAt(slider.position).toFixed(1)
    }
}

This QML method was introduced in QtQuick.Controls 2.1.

See also value and position.


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