|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
效果:点击窗口中间那个方块后消失
知识点1:canvas里画贝塞尔曲线(如不知道原理可观看小甲鱼windows API编程里有介绍)
知识点2:学会使用Loader加载跟取消对象
我们今天把ManiForm.ui.qml这个文件删除,直接用main,qml文件写代码:
- import QtQuick 2.5
- import QtQuick.Window 2.2
- Window {
- visible: true
- width: 640
- height: 480
- title: qsTr("Hello World")
- Component{
- id:rect
- Rectangle{
- width:100
- height: 100
- color:"green"
- Canvas{
- id:line
- width:parent.width
- height: parent.height
- onPaint: {
- var ctx = getContext("2d")
- ctx.lineWidth = 2
- ctx.strokeStyle = "red"
- ctx.bezierCurveTo(0,height-1,width-1,height/2,width/4,height/4)//后两个参数是位置坐标
- ctx.stroke()
- }
- }
- }
- }
- Loader{
- id:ld
- anchors.centerIn: parent
- sourceComponent:rect
- MouseArea{
- anchors.fill: parent
- onClicked: {
- ld.sourceComponent=null
- }
- }
- }
- }
复制代码
Preview: 明天介绍Listview对象的使用 |
|