鱼C论坛

 找回密码
 立即注册
查看: 3231|回复: 1

[技术原创] QT动画制作(十)

[复制链接]
发表于 2017-3-1 10:33:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
效果:
jdfw.gif
知识点1:学会设定项目的状态State
知识点2:学会正弦运动
还是新建QT项目,然后在 / 下新建个Rect.qml文件,代码如下
  1. import QtQuick 2.4

  2. Item {
  3.     MouseArea{//确定鼠标区域
  4.         anchors.fill: parent
  5.         onClicked: text.state="green"
  6.     }

  7.     Text{
  8.         id:text
  9.         anchors.centerIn: parent
  10.         font.pointSize: 24//字号24
  11.         font.bold: true//设定粗体字
  12.         text:"I love FishC"
  13.         state: "red"//设定初始状态为红色
  14.         /*这是一个设定状态的数组,里面可以设置多种状态*/
  15.         states: [State {//设定一种颜色为红色的状态
  16.             name: "red"
  17.             PropertyChanges {
  18.                 target: text//设定目标
  19.                 color:"red"
  20.             }

  21.         },
  22.             State{
  23.                 name:"green"
  24.                 PropertyChanges{
  25.                     target:text
  26.                     color:"green"
  27.                 }
  28.             }
  29.         ]
  30.         transitions: Transition{//设定状态变化时的动画渐变效果
  31.                 from:"red"
  32.                 to:"green"
  33.             PropertyAnimation{
  34.                 target:text
  35.                 property:"color"
  36.                 duration:1000
  37.             }
  38.             }
  39.         /*做正弦曲线运动*/
  40.         XAnimator on x{
  41.             from:100
  42.             to:400
  43.             duration:10000
  44.             loops:Animator.Infinite
  45.             easing.type: Easing.SineCurve
  46.         }
  47.         YAnimator on y{
  48.             from:100
  49.             to:400
  50.             duration:5000
  51.             loops:Animator.Infinite
  52.             easing.type: Easing.SineCurve
  53.         }

  54.     }


  55. }
复制代码

main.qml文件:
  1. import QtQuick 2.5
  2. import QtQuick.Window 2.2

  3. Window {
  4.     visible: true
  5.     width: 640
  6.     height: 480
  7.     title: qsTr("Hello World")

  8.     MainForm {
  9.         anchors.fill: parent

  10.     }
  11. }
复制代码

MainForm.ui.qml文件:
  1. import QtQuick 2.5

  2. Rect{}
复制代码

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-3-1 13:30:54 | 显示全部楼层
看过
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-28 02:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表