禁用QML滑块的鼠标滚轮 [英] Disable mouse wheel for QML Slider

查看:477
本文介绍了禁用QML滑块的鼠标滚轮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够用鼠标滚轮(或触摸板上的两根手指)滚动Flickable 而无需更改可能包含的Slider s .

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
                }
            }
        }
    }
}

好像以前有一些试图解决此问题 ,但没有成功.

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

编辑:仅与Controls 1.x相关,因为从2.0版本开始,控件似乎没有此问题.

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

推荐答案

此处的问题是为我完成的./p>

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

这可能不适用于其他控件(例如ComboBox).

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

这篇关于禁用QML滑块的鼠标滚轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆