gpt4 book ai didi

qt - QML:仅当鼠标进入图像时动画

转载 作者:行者123 更新时间:2023-12-04 13:24:52 25 4
gpt4 key购买 nike

我想在鼠标移到图像上时制作动画,而不是在鼠标离开图像时制作动画。

Item{
width: 800
height:800
Rectangle{
id: blueRec
width: 100; height: 100; color: "blue"
MouseArea{
anchors.fill: parent
onClicked: {
im1.visible = true
im1.source = "1.png"
}
}
}
Image {
id: im1
scale: im1MouseArea.containsMouse ? 0.8 : 1.0
Behavior on scale {
NumberAnimation{
id: anim
from: 0.95
to: 1
duration: 400
easing.type: Easing.OutBounce
}
}
MouseArea{
id: im1MouseArea
hoverEnabled: true
anchors.fill: parent
}
}

}

当鼠标离开图像时,上面的代码也制作动画。

有人可以帮忙吗?

最佳答案

设置比例然后触发改变比例的动画似乎是一种奇怪的方法。如果我是你,我会将其分解为状态并将动画设置为在适当的转换时触发。

下面是如何做到这一点的一个例子:

Image {
id: im1

states: [ "mouseIn", "mouseOut" ]
state: "mouseOut"

transitions: [
Transition {
from: "*"
to: "mouseIn"
NumberAnimation {
target: im1
properties: "scale"
from: 0.95
to: 1
duration: 400
easing.type: Easing.OutBounce
}
}
]

MouseArea{
id: im1MouseArea
hoverEnabled: true
anchors.fill: parent

onContainsMouseChanged: {
im1.state = containsMouse ? "mouseIn" : "mouseOut"
}
}
}

关于qt - QML:仅当鼠标进入图像时动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29906932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com