将QML ToolTip与Label一起使用 [英] Use QML ToolTip with Label
本文介绍了将QML ToolTip与Label一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将 ToolTip 与一个TextField.这可以正常工作.
I'm using a ToolTip with a TextField. This works properly.
RowLayout {
property string toolTipText
TextField {
hoverEnabled: true
ToolTip.visible: tooltipText ? hovered : false
ToolTip.text: tooltipText
}
}
但是带有标签,它将无法正常工作.
hoverEnabled
在标签组件中不可用.所以我用MouseArea
But with a Label it wont work properly.
hoverEnabled
is not available in the Label Component. So i've tried it with a MouseArea
RowLayout {
property string toolTipText
Label {
MouseArea {
anchors.fill: parent
hoverEnabled: true
ToolTip.visible: tooltipText ? hovered : false
ToolTip.text: tooltipText
}
}
}
将显示工具提示,但将鼠标悬停在标签上时,不会出现这种情况.它实际上在进入窗口时显示.
The ToolTip will be shown, but not when mouseover the Label. It actually shows when entering the Window.
有什么解决办法吗?
推荐答案
MouseArea没有工具提示,但是具有Label,因此您必须移动它并使用MouseArea的containsMouse属性激活它:
MouseArea does not have the ToolTip but the Label, so that you must move it and activate it using the containsMouse property of MouseArea:
RowLayout {
Label {
text: "label"
property string toolTipText: "message"
ToolTip.text: toolTipText
ToolTip.visible: toolTipText ? ma.containsMouse : false
MouseArea {
id: ma
anchors.fill: parent
hoverEnabled: true
}
}
}
这篇关于将QML ToolTip与Label一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文