我有一个 TreeView
与自定义委托 . 代理使用 ToolTip
,如果代表 mouseArea
悬停,将显示该代表 . 但是,这个mouseArea在我的 TreeView
中选择了一行 . 我想点击不会传播到 TreeView
的mouseArea . 我尝试了 propagateComposedEvents
和 mouse.accepted=false
,但选择仍然不起作用 .
TreeView {
id: view
anchors.fill: parent
sortIndicatorVisible: true
model: fileSystemModel
rootIndex: rootPathIndex
selection: sel
selectionMode: 2
Component {
id: mycomp
Item {
id: myitm
Row{
id: myrow
CheckBox{
id: cbox
anchors.baseline: ctext.baseline
}
Text{
id: ctext
text: styleData.value
color: styleData.textColor
width: namecolumn.width-cbox.width-myrow.x
elide: Text.ElideRight
}
}
NC.ToolTip {
id: ttip
parent: ctext
text: qsTr(styleData.value)
delay: 500
visible: mouseArea.containsMouse
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
onClicked: {
mouse.accepted = false
}
}
}
}
1 回答
只需将MouseArea的acceptedButtons属性设置为Qt.NoButton即可 . 此属性确定了区域将处理的按钮 . NoButton会导致该区域报告悬停事件,但不会处理任何点击 .
请在此处查看该属性的完整文档:
http://doc.qt.io/qt-5/qml-qtquick-mousearea.html#acceptedButtons-prop