代码之家  ›  专栏  ›  技术社区  ›  MusiGenesis

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

  •  6
  • MusiGenesis  · 技术社区  · 7 年前

    TextArea <IMG ...> 代理中的标记 ListView . 我把它设置为只读(而不是禁用),因为我需要文本中的超链接是可点击的,所以我需要利用它的超链接 onLinkActivated Label 标签 <图像…>

    我的问题是 文本域 处理鼠标滚轮事件,即使它是只读的,所以如果光标恰好位于某个可见的 控件 不会响应鼠标滚轮事件(因此不会滚动)。换言之 文本域 正在捕获鼠标滚轮事件,我希望它不要这样做。

    wheelEnabled: 财产,但是 文本域

    下面是演示问题的最小代码示例:

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

    控件),鼠标滚轮按预期工作。但是如果你把鼠标放在 在任何一行中 不会用鼠标滚轮滚动(因为只读 TextView 正在捕获事件)。

    2 回复  |  直到 7 年前
        1
  •  3
  •   MusiGenesis    7 年前

    这其实很简单,可惜我浪费了赏金。所有这些都需要一个 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
            }
        }
    }
    

    这会忽略新闻和发布事件,因此单击 文本域 仍然有效,但它拦截鼠标滚轮事件并将其应用于移动 ScrollView 好像文本区域不在那里。

        2
  •  0
  •   bardao    7 年前

    试试这个:

    import QtQuick 2.4
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.3
    
    Window {
        visible: true
        width: 400
        height: 200
    
        TextArea {
            id: text
            anchors.fill: parent
    
            text: "Current\ntext\n\\to\nmove\ndown\ndown\ndown
                   \ndown\ndown\ndown\ndown\ndown\ndown\ndown"
    
            flickableItem.interactive: false
        }
    }
    

    TextArea flickableItem.enabled 财产。既然你被困住了!t5.6这应该对你有用。

    编辑:更改为 flickableItem.interactive 相反。