只是一个非常简单的案例,第一次单击鼠标,幕布式展开窗口,第二次单击鼠标,幕布式缩小窗口,如此反复
这里特殊的地方有;
1. 在判断是否相等时候,用的三个等号来判断,而不是两个;
2. 自己定义一个变量,根据情况调用start函数来实现。
代码;
import QtQuick 2.3
import QtQuick.Window 2.2
Window {
id:win
visible: true
width: 500
height: 500
property var donghua;
Rectangle{
anchors.fill: parent
color: "red"
id:root
PropertyAnimation{
id:down
target: win
property: "height"
from:0
to:500
duration: 5000
onStarted: {
donghua=up//赋值
}
}
PropertyAnimation{
id:up
target: win
property: "height"
from:500
to:100
duration: 5000
onStarted: {
donghua=down}
}
MouseArea{
anchors.fill: parent
onClicked:{
if(win.donghua===down|win.donghua===undefined)
{
down.start()
}
else{
up.start()
}
}
}
}
}