鱼C论坛

 找回密码
 立即注册
查看: 2667|回复: 0

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

[复制链接]
发表于 2017-3-16 09:46:00 | 显示全部楼层 |阅读模式

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

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

x
效果:点击窗口中间那个方块后消失
知识点1:canvas里画贝塞尔曲线(如不知道原理可观看小甲鱼windows API编程里有介绍)
知识点2:学会使用Loader加载跟取消对象
我们今天把ManiForm.ui.qml这个文件删除,直接用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.     Component{
  9.         id:rect
  10.         Rectangle{
  11.             width:100
  12.             height: 100
  13.             color:"green"
  14.         Canvas{
  15.             id:line
  16.             width:parent.width
  17.             height: parent.height
  18.             onPaint: {
  19.                 var ctx = getContext("2d")
  20.                 ctx.lineWidth = 2
  21.                 ctx.strokeStyle = "red"
  22.                 ctx.bezierCurveTo(0,height-1,width-1,height/2,width/4,height/4)//后两个参数是位置坐标
  23.                 ctx.stroke()
  24.             }
  25.         }

  26.         }
  27.     }
  28.     Loader{
  29.         id:ld
  30.         anchors.centerIn: parent
  31.         sourceComponent:rect
  32.         MouseArea{
  33.             anchors.fill: parent
  34.             onClicked: {
  35.                 ld.sourceComponent=null
  36.             }
  37.         }
  38.     }


  39. }
复制代码

Preview: 明天介绍Listview对象的使用

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-27 14:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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