彩阳:points[0]和points[1]。
 (2014-09-08 09:30) 
 
追问一句,从哪些地方可以知道这中基本的定义知识,我查了一些文档都没有见过。。。
我定义的是这样的一块画布,现在可以拖拽画矩形了,可是fox.rect()有句报错提示: Cannot read property 'x' of undefined,:
import QtQuick 2.1
import QtQml 2.2
Canvas {
        id: shapeCanvas
        anchors.fill: parent
        property  string  shapeName: "rect"
        property var points:new Array
      onPaint: {
           var fox = getContext("2d")
            fox.clearRect(0, 0, width, height)
            fox.save()
             fox.rect(points[0].x,points[0].y,points[1].x-points[0].x,points[1].y-points[0].y)             
            fox.strokeStyle = "red"
              fox.closePath()
                fox.fill
                fox.stroke()
                fox.restore()
         }
           MouseArea {
                  id: markPaint
                  anchors.fill: parent
                   onPressed:  {
                       points[0] = Qt.point(mouse.x,mouse.y)
                   }
                   onReleased: {
                   points[1] = Qt.point(mouse.x,mouse.y)
                   shapeCanvas.requestPaint()
                   }
                   onPositionChanged: {
                  points[1] = Qt.point(mouse.x,mouse.y)
                            shapeCanvas.requestPaint()
                   }
              }
    }