修复qml项目行为

修复qml项目行为

问题描述:

我在qml上有代码,它应该通过单击将它分成4个方块。修复qml项目行为

import QtQuick 2.0 

Rectangle { 
    Component { 
     id: squareComponent 
     Rectangle { 
      property int sideLenght: 500 
      width: sideLenght 
      height: sideLenght 
      color: "orange" 
      MouseArea { 
       anchors.fill: parent 
       onClicked: { 
        var first = squareComponent.createObject(parent) 
        var second = squareComponent.createObject(parent) 
        var third = squareComponent.createObject(parent) 
        var fourth = squareComponent.createObject(parent) 

        var sideLenght = parent.sideLenght/2 

        first.sideLenght = sideLenght 
        second.sideLenght = sideLenght 
        third.sideLenght = sideLenght 
        fourth.sideLenght = sideLenght 

        var x = parent.x 
        var y = parent.y 
        console.log(x, y) 

        first.x = x 
        first.y = y 
        first.color = "red" 
        console.log("first", first.x, first.y) 

        second.x = first.x + sideLenght 
        second.y = first.y 
        second.color = "orange" 
        console.log("second", second.x, second.y) 

        third.x = first.x 
        third.y = first.y + sideLenght 
        third.color = "blue" 
        console.log("third", third.x, third.y) 

        fourth.x = first.x + sideLenght 
        fourth.y = first.y + sideLenght 
        fourth.color = "black" 
        console.log("fourth", fourth.x, fourth.y, "\n\n") 

        parent.sideLenght = 0 
       } 
      } 
     } 
    } 

    Component.onCompleted: squareComponent.createObject(parent) 
} 

它们是分开的,但划分唯一正确的平方(0,0),其它的是通过母体的量为x或y的偏移量。 Qt 5.0.1。我如何解决这个问题,这是一个错误吗?

伐木说,元素是正确的,但他们其实不是。

这就是我得到的输出QtQuick 1.1。这在Qt 5.0.1中有所不同吗?

Output