我正在使用TextArea
在委托中显示带有嵌入式<IMG ...>
标签的多行文本,用于ListView
。我将其设置为只读(而不是禁用(,因为我需要文本中的超链接可单击,因此我需要使用它onLinkActivated
事件处理程序。这通常需要Label
(不处理鼠标滚轮事件(,但是当文本在 HTML 中包含<IMG ...>
标记时,Label
不会正确呈现换行符。
我遇到的问题是,即使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
}
}
}
}
}
如果将鼠标光标悬停在此列表视图的右侧(即不在行中的TextArea
控件上(,则鼠标滚轮将按预期工作。但是,如果将鼠标光标悬停在任何行中的TextArea
上,则ListView
将不会随鼠标滚轮滚动(因为 readOnlyTextView
正在捕获事件(。
这实际上很容易,可惜我浪费了赏金。所有这些都需要一个位于TextArea
上的MouseArea
,如下所示:
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
}
}
}
这将忽略新闻和发布事件,因此单击TextArea
中的超链接仍然有效,但它会截获鼠标滚轮事件并将其应用于移动ScrollView
,就好像 TextArea 不存在一样。
试试这个:
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: "Currentntextn\tonmovendownndownndown
ndownndownndownndownndownndownndown"
flickableItem.interactive: false
}
}
TextArea
拥有flickableItem.enabled
财产。由于您坚持使用!t 5.6,因此这应该对您有用。
编辑:改为flickableItem.interactive
。