如何在不禁用整个控件的情况下禁用TextArea的鼠标滚轮?

Mus*_*sis 6 qt qml qtquickcontrols

我正在使用a 在委托中TextArea显示带有嵌入<IMG ...>标签的多行文本ListView.我把它设置为只读(而不是禁用),因为我需要文本中的超链接是可点击的,所以我需要使用它的onLinkActivated事件处理程序.这通常是需要a Label(不处理鼠标滚轮事件)的东西,但是Label当文本<IMG ...>在HTML中包含标记时,a 不能正确地呈现换行符.

我遇到的问题是TextArea处理鼠标滚轮事件,即使它是只读的,所以如果光标碰巧超过其中一个可见TextArea控件,ListView则不会响应鼠标滚轮事件(因此它不会滚动).换句话说,TextArea正在捕获鼠标滚轮事件,我希望它不会这样做.

我在文档中看到控件有一个wheelEnabled:属性,但TextArea似乎不支持这个.

更新:这是一个演示问题的最小代码示例:

import QtQuick.Controls 1.4 as Controls

Rectangle {

    id: test

    color: "white"
    width: 300
    anchors {
        left: parent.left
        top: parent.top
        bottom: parent.bottom
    }

    Controls.ScrollView {

        id: _scrollview

        anchors.fill: parent

        ListView {
            anchors.fill: parent
            model: 100

            delegate: Rectangle {
                id: tableRow
                width: test.width
                height: 50
                color: "yellow"

                TextArea {
                    width: test.width / 2
                    height: tableRow.height
                    readOnly: true
                    text: "Row # " + index
                }

            }

        }

    }

}
Run Code Online (Sandbox Code Playgroud)

如果将鼠标光标放在此列表视图的右侧(即不在TextArea行中的控件上方),鼠标滚轮将按预期工作.但是如果将鼠标光标放在TextArea任何行中,ListView则不会使用鼠标滚轮滚动(因为readOnly TextView正在捕获事件).

Mus*_*sis 3

这实际上很简单,可惜我浪费了赏金。所有这一切都需要一个MouseArea定位,如下所示TextArea

MouseArea {
    anchors.fill: txtTester
    onPressed: {
        mouse.accepted = false
    }
    onReleased: {
        mouse.accepted = false
    }

    property int scrollValue: 15
    onWheel: {
        if (wheel.angleDelta.y < 0) {
            //make sure not to scroll too far
            if (!_scrollview.flickableItem.atYEnd)
                _scrollview.flickableItem.contentY += scrollValue
        }
        else {
            //make sure not to scroll too far
            if (!_scrollview.flickableItem.atYBeginning)
                _scrollview.flickableItem.contentY -= scrollValue
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这会忽略按下和释放事件,因此单击 中的超链接TextArea仍然有效,但它会拦截鼠标滚轮事件并将它们应用于移动ScrollView,就好像 TextArea 不存在一样。