2013-02-19 34 views
0

我在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。我如何解決這個問題,這是一個錯誤嗎?

伐木說,元素是正確的,但他們其實不是。

回答

0

這就是我得到的輸出QtQuick 1.1。這在Qt 5.0.1中有所不同嗎?

Output