我有一个带有自定义委托的TreeView。委托使用ToolTip,如果挂起委托mouseArea,则会显示该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
}
}
}
}发布于 2018-04-30 15:23:26
只需将MouseArea的MouseArea属性设置为Qt.NoButton即可。此属性确定该区域将处理的按钮。NoButton会使该区域报告悬停事件,但不会处理任何单击。
请参阅此处有关该属性的完整文档:
http://doc.qt.io/qt-5/qml-qtquick-mousearea.html#acceptedButtons-prop
https://stackoverflow.com/questions/50103461
复制相似问题