Slider support for tickmarks?
-
Re: How to add tick marks in QML Slider: QtQuick.Controls 1.x provided a tickmarksEnabled property, but QtQuick.Controls 2 removed that property for some reason - why? Is there a straightforward way to support this extremely common use case?
Thanks! -
If you look at the example animation from the latest version of documentation (
Qt 6.7
), you can see a slider having tick marks...But dont ask me how it's done ;-)
-
@Pl45m4 - That has nothing to do with visible tickmarks, those are just methods to control slider with stepping size. There does not seem to be any provision with later/current versions of Qt. If stepSize it set, the slider will pause at intervals as if it were inline with a corresponding tickmark, instead, we use 'label'.
-
@Pl45m4 - they are example/legacy images, probably from previous releases of Slider, it looks to me like 'tickmarks' were dropped in releases beyond 5.15 https://doc.qt.io/qt-5/qml-qtquick-controls-slider.html seeing as QtQuick.Controls 1.4 is also obsolete.
-
@Tom-asso - it does seem that way. I've been making speedometers using a CircularSlider, which did not have tickmarks, so i had to find a way to add tickmarks. I did this using Repeater with Rectangle for ticks and Label for digits.
This works; kinda, it's crude somewhat and not entirely accurate to the eye;
``` Column { id: column width: parent.width anchors.centerIn: parent Slider { value: 0.5 width: 1000 stepSize: 0.1 minimumValue: 0.0 maximumValue: 1.0 anchors.horizontalCenter: parent.horizontalCenter Row { spacing: 68 anchors { verticalCenterOffset: 40 verticalCenter: parent.verticalCenter horizontalCenter: parent.horizontalCenter } Repeater { model: 11 Rectangle { width: 2 height: 25 Label { text: index font.pixelSize: 48 x: -12.5; y: 30 } } } } } }
-
@Tom-asso For some reason the Material style
Slider
has tickmarks when snapMode is SnapAlways and it has a suited stepSize. It doesn't seem other modes have tickmarks.You could add it to the background with a Repeater of Rectangle.