赞
踩
在使用qml做程序时,因为需要toolTip,但是QtQuick除了最初的版本的所有组件都有这个元素之外,之后的版本将之删除了,于是我们只能自己来写toolTip,经过查找,笔者最终在Qt官网上找到了解决方法,以下分享给大家
第一种方法跟标准的toolTip很接近,其作者是Xander84。这种实现方式将toolTip的浮现和隐藏都有各自的函数实现,并且当其隐藏后可以将之注销,代码如下
import QtQuick 2.2
Rectangle {
id: tooltip
property alias text: tooltipText.text
property alias textItem: tooltipText
property int fadeInDelay: 500
property int fadeOutDelay: 500
property bool autoHide: true
property alias autoHideDelay: hideTimer.interval
property bool destroyOnHide: true
function show() {
state = "showing"
if (hideTimer.running) {
hideTimer.restart()
}
}
function hide() {
if (hideTimer.running) {
hideTimer.stop()
}
state = "hidden"
}
width: tooltipText.width + 20
height: tooltipText.height + 10
color: "#dd000000"
radius: 6
opacity: 0
Text {
id: tooltipText
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter
color: "white"
font.pointSize: 10
font.bold: true
}
MouseArea {
anchors.f

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。