import QtQuick
import QtQuick.WindowWindow {width: 800height: 600visible: truetitle: qsTr("Test Anchors")///锚点 上下左右Rectangle{id: anchor1width:200height: 150color:"#EEEEEE"Rectangle{id:rect1width:50height:50color: "red"Text{text:"rect1"}}Rectangle{id:rect2width:50height:50color: "blue"Text{text:"rect2"}anchors.left: rect1.right}Rectangle{id:rect3width:50height:50color: "green"Text{text:"rect3"}anchors.top: rect1.bottom}Rectangle{id:rect4width:50height:50color: "pink"Text{text:"rect4"}anchors.left: rect3.rightanchors.top: rect2.bottom}}///锚点 动态大小Rectangle{id: anchor2anchors.left:anchor1.rightanchors.leftMargin: 5 //左侧间距width:200height: 150color:"#EEEEEE"Rectangle{id:leftpagewidth: 50color:"blue"anchors.top: parent.top //自动拉升高度anchors.bottom: parent.bottomText{text:"left"}}Rectangle{id:mainpagecolor:"pink"anchors.top: parent.top //自动拉升高度anchors.bottom: parent.bottomanchors.left:leftpage.right //自动拉升宽度anchors.right: rightpage.leftText{text:"main"}}Rectangle{id:rightpagewidth: 50color:"green"anchors.top: parent.top //自动拉升高度anchors.bottom: parent.bottomanchors.right: parent.rightText{text:"right"}}MouseArea{anchors.fill: parentonClicked:{parent.width +=10parent.height +=10}}}Rectangle{id:anchor3//通过anchor2、和窗口 锚定宽高和位置anchors.left: anchor2.rightanchors.right: parent.rightanchors.top: anchor2.topanchors.bottom: anchor2.bottomanchors.leftMargin: 5color:"#EEEEEE"//水平居中Rectangle{id:hcentercolor:"red"width:50//拉升高度anchors.top: parent.topanchors.bottom: parent.bottom//水平居中anchors.horizontalCenter: parent.horizontalCenter}Rectangle{width:50height: 50color:"blue"//垂直居中anchors.verticalCenter:hcenter.verticalCenteranchors.left: hcenter.right}//完全居中Rectangle{width:50height: 50color:"yellow"anchors.centerIn: parent}}}
推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家:
零声白金学习卡(含基础架构/高性能存储/golang云原生/音视频/Linux内核)
https://xxetb.xet.tech/s/3Zqhgt