main.qml
@import QtQuick 2.0
Item{
id:root
width: 640
height: 540
property int count:0
property var rectangle:[]
Rectangle {
id:rect
anchors.fill: parent
MouseArea {
anchors.fill: parent
onClicked: {
rectangle[count]=Qt.createComponent("Rect.qml").createObject(parent, {x: mouseX, y: mouseY})
count++
//here we can create number of rectangles,
//rectangle[0].width will have the width of first rectangle
//rectangle[0].height will have the height of first rectangle
//rectangle[0].x will have the xpos of first rectangle
//rectangle[0].y will have the ypos of first rectangle
/editing a rectangle after its creation will be automatically updated in the corresponding array,so we need not to be care about that/
//count will have number of rectangles created
}
}
}
}
@
Rect.qml
@
import QtQuick 2.0
Rectangle {
id: rect
color: "yellow"
width: 50
height: 50
MouseArea {
id: right
width: 8
height: parent.height
anchors.right: parent.right
property int oldMouseX
hoverEnabled: true
onPressed: {
oldMouseX = mouseX
}
onPositionChanged: {
if (pressed) {
rect.width = rect.width + (mouseX - oldMouseX)
}
}
}
}
@