Qt 프로그래밍/Basic Qt
[Qt 프로그래밍] QML, Rectangle 위치 지정
kwoss2341
2021. 2. 22. 21:59
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.2
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Rectangle
{
id:r1
width:100
height:100
anchors.centerIn: parent
color:"white"
border.color: "black"
border.width: 5
Text {
id: t1
text: qsTr("r1")
anchors.centerIn: parent
}
}
Rectangle
{
id:r2
width:100
height:100
anchors.left: r1.right
anchors.bottom:r1.bottom
color:"white"
border.color: "black"
border.width: 5
}
Rectangle
{
id:r3
width:100
height:100
anchors.left: r1.left
anchors.top:r1.bottom
color:"white"
border.color: "black"
border.width: 5
Text {
id: t3
text: qsTr("r3")
anchors.centerIn: parent
}
}
Rectangle
{
id:r4
width:100
height:100
anchors.left: r3.right
anchors.bottom:r3.bottom
color:"white"
border.color: "black"
border.width: 5
Text {
id: t4
text: qsTr("r4")
anchors.centerIn: parent
}
}
}
r1 사각형을 중심으로
r2,r3,r4 사각형의 위치를 지정할 수 있다.
anchors.left:
anchors.top
anchors.bottom
속성을 잘 이용하자.