๐๐ป QT QML์์ ๊ฐ๋ก ์ธ๋ก ๋ ์ด์์์ ๋ํ ์ค๋ช
๊ณผ ์ฝ๋์
๋๋ค.
Description and code for horizontal and vertical layout in QT QML.
๐๐ป๊ฐ๋ก ,์ธ๋ก๋ ์ด์์์๋ Column,Row,ColumnLayout,RowLayout์ด ์์ต๋๋ค.
For horizontal and vertical layouts, there are Column, Row, ColumnLayout, and RowLayout.
๐๐ป ColumnLayout๊ณผ RowLayout์ ๋ฐ์ํ UI๋ ์ฐฝ ๋ฆฌ์ฌ์ด์ฆ ๋์ UI์ ์ ํฉํฉ๋๋ค.
ColumnLayout and RowLayout are suitable for responsive UI or UI that responds to window resizing.
1.Colum {} : ์์ดํ ์ ์ธ๋ก๋ก ์ ๋ ฌํ๊ธฐ ์ํด์ ์ฌ์ฉํฉ๋๋ค. / Used to align items vertically.
2.Row {} : ์์ดํ ์ ๊ฐ๋ก๋ก ์ ๋ ฌํ๊ธฐ ์ํด์ ์ฌ์ฉํฉ๋๋ค / Used to align items horizontally
3.ColumnLayout {} :
— Column๊ณผ ๊ฐ์ด ์ธ๋ก๋ก ์ ๋ ฌํ๊ธฐ ์ํด์ ์ฌ์ฉํฉ๋๋ค. / Used to align vertically, like a column.
— ์ข๋ ๋ณต์กํ ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ ๋ ์ฌ์ฉํฉ๋๋ค. / Used when using more complex structures.
4.RowLayout {} :
— Row์ ๊ฐ์ด ๊ฐ๋ก๋ก ์ ๋ ฌํ๊ธฐ ์ํด์ ์ฌ์ฉํฉ๋๋ค. / Used to align horizontally, like Row.
— ์ข ๋ ๋ณต์กํฉ ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ ๋ ์ฌ์ฉํฉ๋๋ค. / Used when using more complex structures.
6.anchor :
— QML์์ UI ์์์ ์์น๋ฅผ ๋ค๋ฅธ ์์(๋๋ ๋ถ๋ชจ)์ ํน์ ์์น์ ๋ง์ถฐ์ ๋ฐฐ์นํ๊ธฐ ์ํ ์์ฑ ์์คํ
.
A property system in QML for positioning UI elements relative to a specific location in another element (or parent).
5.์ฝ๋ / Code
โ๏ธMain.qml
— ์ฝ๋์๋ณด์๋ฉด ListModel๊ณผ Repeater๊ฐ ์์ต๋๋ค.
If you look at the code, there is a ListModel and a Repeater.
— ListModel์ ๋ฐฐ์ด,Repeater๋ ๋๋ถ๋ถ์ ํ๋ก๊ทธ๋๋ฐ์ธ์ด์์ ์ฌ์ฉํ๋ ๋ฐ๋ณต๋ฌธ์ด๋ผ๊ณ ์ดํดํ์
๋ ๋ฉ๋๋ค.
You can understand ListModel as an array, and Repeater as a loop used in most programming languages.
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
ApplicationWindow {
visible: true
width: 800
height: 600
title: "Layout,ListModel"
// ๋ฐ์ดํฐ ๋ชจ๋ธ ์ ์
ListModel {
id: fruitModel
ListElement { name: "์ฌ๊ณผ/Apple" }
ListElement { name: "๋ฐ๋๋/Banana" }
ListElement { name: "ํฌ๋/Grape" }
}
ListModel {
id: gameModel
ListElement { name : "Assassin's Creed" }
ListElement { name : "Uncharted3" }
ListElement { name : "Horizon zero dawn" }
}
// ํ๋ฉด์ ํ์
Column {
id:column1
anchors.centerIn: parent // vertical,horizontal๋ชจ๋ ๊ฐ์ด๋ฐ ์ ๋ ฌ / Center align both vertically and horizontally
Repeater {
model: fruitModel
Text {
text: model.name // ListElement ์์ name ์์ฑ ์ฌ์ฉ / Using the name property in ListElement
font.pixelSize: 18
}
}
}
// ํ๋ฉด์ ํ์
// anchors.centerIn: column1 : ๊ฐ๋ก,์ธ๋ก๋ฅผ ๋ชจ๋ ๊ฐ์ด๋ฐ ์ ๋ ฌ ๋จ,์๋ชป ์ฌ์ฉํ ๊ฒฝ์ฐ ์ถฉ๋ ์ค๋ฅ ์์.
// Display on screen
// anchors.centerIn: column1 : Centers both horizontally and vertically. If used incorrectly, a crash error may occur.
Row {
id:row1
//anchors.centerIn: column1
anchors.top: column1.bottom // Column ๋ฐ๋ก ์๋ ์์น / Located just below the column
anchors.horizontalCenter: parent.horizontalCenter // ๊ฐ๋ก ๊ฐ์ด๋ฐ ์ ๋ ฌ / horizontally center aligned
anchors.topMargin: 20 // ์์ชฝ ์ฌ๋ฐฑ / top margin
Repeater {
model: fruitModel
Text {
text: model.name
font.pixelSize : 18
}
}
}
ColumnLayout {
id:column2
anchors.top:row1.bottom
anchors.horizontalCenter: row1.horizontalCenter // row1์ ๊ฐ๋ก ์ค์ฌ์ ์ ๋ ฌ / Align to the horizontal center of row1
anchors.topMargin: 20
Repeater {
model: gameModel
Text {
text:model.name
font.pixelSize : 18
}
}
}
RowLayout {
id:row2
anchors.top:column2.bottom
anchors.horizontalCenter: row1.horizontalCenter // row1์ ๊ฐ๋ก ์ค์ฌ์ ์ ๋ ฌ / Align to the horizontal center of row1
anchors.topMargin: 20
Repeater {
model: gameModel
Text {
text:model.name
font.pixelSize : 18
}
}
}
}
6.์คํฌ๋ฆฐ์ท / ScreenShot
