修复qml项目行为

时间:2013-02-19 16:48:34

标签: qt qml qt5

我在qml上有代码,应该通过点击将其划分为4个方格。

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。我如何解决这个问题,这是一个错误吗?

记录表明元素是正确的,但事实并非如此。

1 个答案:

答案 0 :(得分:0)

这是QtQuick 1.1输出的结果。这在Qt 5.0.1中是不同的吗?

Output