QML 属性过渡动画的简单演示

QML的一大好处就是动画特别简单,这里给出变换(平移即修改x,y的值、旋转即修改rotation的值、缩放即修改scale的值)和透明度opactiy以及颜色color属性的动画代码的简单演示,并理解anchor布局的作用。

代码如下:

import QtQuick
import Qt.labs.platform
import QtQuick.Controls
Window {
    id: mainWindow
    title: "Main Window"
    color: "#456"

    width:640
    height:480
    visible: true

    Rectangle{
        id: rr  //red rectangle
        width: 100
        height: 100
        color: "red"
    }
    Rectangle{
        id: gr
        anchors.left: rr.left
        anchors.top: rr.bottom
        width: 100
        height: 100
        color: "green"
    }
    Rectangle{
        id: br
        anchors.left: gr.left
        anchors.top: gr.bottom
        width: 100
        height: 100
        color: "blue"


    }

    readonly property int during: 2000
    //red rect (move and spin)
    PropertyAnimation{
        target: rr
        property: "x"
        from: 0
        to : mainWindow.width
        duration:during
        running: true
        loops: 500
    }
    PropertyAnimation{
        target: rr
        property: "rotation"
        from:0
        to: 360
        duration:during
        running: true
        loops: 500
    }
    //green rect
    PropertyAnimation{
        target: gr
        from: 1
        to: 0
        properties: "scale,opacity"
        running: true
        duration: during
        loops: 500
    }
    //blue rect
    ColorAnimation  {
        target: br
        from: Qt.rgba(0,0,1,1)
        to: Qt.rgba(1,0,1,1)
        property: "color"
        duration: during
        loops:500
        running: true
    }
}
 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值