为什么列高度计算在包含全宽元素时会中断?

时间:2015-06-15 19:01:34

标签: qt qml qt5 qtquick2 qt5.4

我很想知道当Column跨越整个宽度时Row高度计算为何会中断。

在以下代码中切换注释以重现:

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2

ApplicationWindow {
    width: 640
    height: 480
    visible: true

    Column {
        id: col
        anchors {
            left: parent.left
            right: parent.right
        }

        Row {
            id: row
            anchors {
                left: parent.left
//                right: parent.right
            }

            Rectangle {
                color: "green"
                width: 20
                height: 20
            }

            Rectangle {
                color: "red"
                width: 30
                height: 30
            }
        }
    }

    Component.onCompleted: {
        console.log("col.height: " + col.height)
        console.log("col.implicitHeight: " + col.implicitHeight)
        console.log("col.width: " + col.width)
        console.log("col.implicitWidth: " + col.implicitWidth)
        console.log("row.height: " + row.height)
        console.log("row.implicitHeight: " + row.implicitHeight)
        console.log("row.width: " + row.width)
        console.log("row.implicitWidth: " + row.implicitWidth)
    }
}

案例1(如上所述):

col.height: 30
col.implicitHeight: 30
col.width: 0
col.implicitWidth: 50
row.height: 30
row.implicitHeight: 30
row.width: 50
row.implicitWidth: 50

案例2(Row跨越全宽):

col.height: 0
col.implicitHeight: 0
col.width: 0
col.implicitWidth: 0
row.height: 30
row.implicitHeight: 30
row.width: 0
row.implicitWidth: 50

0 个答案:

没有答案