Search code examples
qtqmlqtquick2qtquickcontrols

Disable mouse wheel for QML Slider


I want to be able to scroll Flickable with mouse wheel (or two fingers on touchpad) without changing Sliders it may containt.

Sample code and result application:

import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 1.4

ApplicationWindow {
    id: rootWindow

    visible: true
    width: 400
    height: 200
    title: qsTr("Hello World")

    ScrollView {
        anchors.fill: parent
        flickableItem.flickableDirection: Flickable.VerticalFlick

        Column {
            Repeater {
                model: 40
                Slider {
                    width: rootWindow.width * 0.9
                }
            }
        }
    }
}

result application

Looks like there was some attempt to fix this in the past, but not successful.

EDIT: this relates to Controls 1.x only, as controls doesn't seem to have this issue starting from 2.0 version.


Solution

  • Hack from here did it for me.

    Slider {
        id: slider
        Component.onCompleted: {
            for (var i = 0; i < slider.children.length; ++i) {
                if (slider.children[i].hasOwnProperty("onVerticalWheelMoved") && slider.children[i].hasOwnProperty("onHorizontalWheelMoved")) {
                    slider.children[i].destroy()
                }
            }
        }
    }
    

    This may not work with other controls (e.g. ComboBox).