背景: 文字需要悬浮出现提示说明,需要给Text添加 鼠标悬浮检测,但导致控件能被直接拖动!以下是源代码与解决代码对比:
需注意MouseArea 会对下面控件的MouseArea 进行覆盖,使用需注意
Text {
property bool hovered: mousearea.containsMouse
font.pixelSize: 12
font.weight: Font.Light
color: "#787878"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
HoverHandler {
id: hoverhander
enabled: true
}
}
Text {
property bool hovered: mousearea.containsMouse
font.pixelSize: 12
font.weight: Font.Light
color: "#787878"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
MouseArea {
id: mousearea
anchors.fill: parent
hoverEnabled:true
}
}