Commit a673947e authored by Nate Graham's avatar Nate Graham
Browse files

Slider: handle scrolling

The Plasma and QtWidgets sliders do this too; qqc2-desktop-style Sliders
should do the same for consistency, especially now that there's no
longer a conflict between scrollable controls and any scrollable view
they may live on.

Implementation is more or less copied from ComboBox.qml.

BUG: 417211
FIXED-IN: 5.91
parent 3c313ad8
Pipeline #119940 passed with stage
in 37 seconds
......@@ -45,5 +45,39 @@ T.Slider {
hasFocus: controlRoot.activeFocus
hover: controlRoot.hovered
activeControl: controlRoot.stepSize > 0 ? "ticks" : ""
// `wheelEnabled: true` doesn't work since it doesn't snap to tickmarks,
// so we have to implement the scroll handling ourselves. See
// https://bugreports.qt.io/browse/QTBUG-93081
MouseArea {
property int wheelDelta: 0
anchors {
fill: parent
leftMargin: controlRoot.leftPadding
rightMargin: controlRoot.rightPadding
}
acceptedButtons: Qt.NoButton
onWheel: {
const lastValue = controlRoot.value
const delta = wheel.angleDelta.y || wheel.angleDelta.x
wheelDelta += delta;
// magic number 120 for common "one click"
// See: https://doc.qt.io/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop
while (wheelDelta >= 120) {
wheelDelta -= 120;
controlRoot.decrease();
}
while (wheelDelta <= -120) {
wheelDelta += 120;
controlRoot.increase();
}
if (lastValue !== controlRoot.value) {
controlRoot.moved();
}
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment