qml状态机动画的使用

import QtQuick 2.0
import QtQuick.Controls 2.2
Rectangle {
    id:page
    width: 320
    height: 480
    color: "lightgray"
    Text{
        id:helloText
        text:"hello world"
        y:30
        anchors.horizontalCenter: page.horizontalCenter
        MouseArea{
            id:mousearea
            anchors.fill: parent
        }
        /*
          *添加状态机状态
        */
        states: State{
            /*
              *添加一个状态当鼠标按下时
            */
            name:"down";when:mousearea.pressed === true
            /*
              *当状态触发时要执行的属性值变换
            */
            PropertyChanges {
                target: helloText
                y:160
                rotation:180
                color:"red"
            }
        }
        /*
          *添加一个转换操作过程当状态改变时
        */
        transitions: Transition {
            //from to 代表的是从某个状态到另外一个状态的过程中
            from: ""
            to: "down"
            //reversible 代表的是反过程
            reversible: true
            //添加一个并行的动画 里面的动画都是同时调用
            ParallelAnimation{
                NumberAnimation {
                    properties: "y,rotation"
                    duration: 500
                    easing.type: Easing.InOutQuad
                }

                ColorAnimation {
                    duration: 500
                }
            }
        }
    }
    Grid {
        id: colorPicker
        x: 4
        anchors.bottom: page.bottom
        anchors.bottomMargin: 4
        rows: 2
        columns: 3
        spacing: 3
        /*
         * 处理cell的信号事件,如果cell发送了信号就设置Text的值
        */
        Cell { cellColor: "red"; onClicked: helloText.color = cellColor }
        Cell { cellColor: "green"; onClicked: helloText.color = cellColor }
        Cell { cellColor: "blue"; onClicked: helloText.color = cellColor }
        Cell { cellColor: "yellow"; onClicked: helloText.color = cellColor }
        Cell { cellColor: "steelblue"; onClicked: helloText.color = cellColor }
        Cell { cellColor: "black"; onClicked: helloText.color = cellColor }

    }

    Button {
        id: button
        x: 66
        y: 140
        text: qsTr("Button")
        focusPolicy: Qt.NoFocus
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值