【问题标题】:Fix qml item behavior修复 qml 项目行为
【发布时间】:2013-02-19 16:48:33
【问题描述】:

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

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

【问题讨论】:

    标签: qt qml qt5


    【解决方案1】:

    这是我使用QtQuick 1.1 得到的输出。这在 Qt 5.0.1 中有什么不同吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-21
      • 1970-01-01
      相关资源
      最近更新 更多