qml 锚点

锚点布局 [比x / y 直接定位更加舒服]

任何一个可视组件必须要有高度,宽度,x, y坐标

// 锚点填充
    Rectangle {
        anchors.fill: parent
      //  width: parent.width
      //  height: parent.height
        color: "red"
    }
Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
/*
// 锚点填充
    Rectangle {
        anchors.fill: parent
      //  width: parent.width
      //  height: parent.height
        color: "red"
    }
// 锚点布局
    Item {
        id: xxx
        anchors.fill: parent
    }
    Rectangle {
//        y: 0
//        x: parent.width - 100
        anchors.right: parent.right
        width: 100
        height: 100
        color: "red"
    }
*/
    Item { // 不可见元素
        anchors.fill: parent

        Rectangle { // 不可见元素矩形
//            anchors.right: parent.right // 锚点
//            anchors.bottom: parent.bottom
// 锚点定位父对象垂直和水平中间
//            anchors.centerIn: parent
// 左侧垂直居中
//            anchors.left: parent.left
//            anchors.verticalCenter: parent.verticalCenter
// 上册水平居中
//            anchors.horizontalCenter: parent.horizontalCenter
//            anchors.verticalCenter: parent.top
            width: 100
            height: 100
            color: "red"
        }
    }
}

posted on 2021-05-15 23:27  lodger47  阅读(72)  评论(0编辑  收藏  举报

导航