qml 锚点demo3

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    Item {
        anchors.fill: parent
        Rectangle {
            id: rect
            anchors.fill: parent
            anchors.topMargin: 20
            anchors.leftMargin: 20
            color: "red"

            Component.onCompleted: {
                console.log(rect.width," ",rect.height, " ",rect.x," ",rect.y)
            }
        }
        Rectangle {
            anchors.top:  parent.top
            anchors.left:  parent.left
            anchors.right: rect.left
            height: rect.anchors.topMargin
            color: "green"
        }
        Rectangle {
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            anchors.right: rect.left
            height: rect.anchors.topMargin
            color:  "black"
            z: 1
        }
        Rectangle {
            anchors.top: parent.top
            anchors.right: parent.right
            width: rect.anchors.leftMargin
            height: rect.anchors.topMargin
            color: "blue"
        }
    }
}

posted on 2021-05-16 00:01  lodger47  阅读(24)  评论(0编辑  收藏  举报

导航