이 페이지에서

포지셔너 및 레이아웃

QML에서 항목의 위치를 지정하는 방법에는 여러 가지가 있습니다.

다음은 이에 대한 간략한 개요입니다. 자세한 내용은 『 Qt Quick 의 중요한 개념 - 위치 지정』을 참조하십시오.

수동 배치

항목의 x, y 속성을 설정하여 화면상의 특정 x, y 좌표에 배치할 수 있습니다. 이렇게 하면 시각적 좌표계 규칙에 따라 부모 요소의 왼쪽 상단 모서리를 기준으로 항목의 위치가 설정됩니다.

이러한 속성에 상수 값 대신 바인딩을 사용하는 것과 결합하여, x 및 y 좌표를 적절한 바인딩으로 설정함으로써 상대적 위치 지정을 쉽게 수행할 수도 있습니다.

import QtQuick

Item {
    width: 100; height: 100

    Rectangle {
        // Manually positioned at 20,20
        x: 20
        y: 20
        width: 80
        height: 80
        color: "red"
    }
}

직접 x, y 좌표를 사용하여 배치된 빨간색 사각형

앵커

Item 유형은 다른 Item 유형에 고정할 수 있는 기능을 제공합니다. 각 항목에는 왼쪽, 오른쪽, 수직 중앙, 상단, 하단, 기준선 및 수평 중앙의 일곱 가지 앵커 라인이 있습니다. 세 개의 수직 앵커 라인은 다른 항목의 세 가지 수직 앵커 라인 중 어느 하나에 고정될 수 있으며, 네 개의 수평 앵커 라인은 다른 항목의 수평 앵커 라인에 고정될 수 있습니다.

자세한 내용은 ‘앵커를 사용한 위치 지정(Positioning with Anchors )’ 및 ` anchors property` 문서를 참조하십시오.

import QtQuick

Item {
    width: 200; height: 200

    Rectangle {
        // Anchored to 20px off the top right corner of the parent
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.margins: 20 // Sets all margins at once

        width: 80
        height: 80
        color: "orange"
    }

    Rectangle {
        // Anchored to 20px off the top center corner of the parent.
        // Notice the different group property syntax for 'anchors' compared to
        // the previous Rectangle. Both are valid.
        anchors { horizontalCenter: parent.horizontalCenter; top: parent.top; topMargin: 20 }

        width: 80
        height: 80
        color: "green"
    }
}

앵커를 사용하여 배치된 녹색 및 주황색 직사각형

포지셔너

일련의 타입을 규칙적인 패턴으로 배치하고자 하는 일반적인 경우를 위해, Qt Quick 는 몇 가지 포지셔너 타입을 제공합니다. 포지셔너에 배치된 아이템은 특정 방식으로 자동으로 배치됩니다. 예를 들어, 행 포지셔너( Row )는 아이템을 수평으로 인접하게 배치하여(행(row)을 형성) 배치합니다.

자세한 내용은 ‘아이템 포지셔너’를 참조하십시오.

import QtQuick

Item {
    width: 300; height: 100

    Row { // The "Row" type lays out its child items in a horizontal line
        spacing: 20 // Places 20px of space between items

        Rectangle { width: 80; height: 80; color: "red" }
        Rectangle { width: 80; height: 80; color: "green" }
        Rectangle { width: 80; height: 80; color: "blue" }
    }
}

포지셔너를 사용하여 일렬로 배열된 빨간색, 초록색, 파란색 사각형

레이아웃 유형

레이아웃 유형은 포지셔너와 유사한 방식으로 작동하지만, 레이아웃에 대한 추가적인 미세 조정이나 제한을 허용합니다. 구체적으로, 레이아웃 유형을 사용하면 다음을 수행할 수 있습니다:

  • 텍스트 및 기타 항목의 정렬 방식 설정
  • 할당된 적용 영역의 크기를 자동으로 조정하고 채우기
  • 최소 또는 최대 크기와 같은 크기 제약 조건 설정
  • 레이아웃 내 항목 간의 간격 설정
GroupBox {
    id: gridBox
    title: "Grid layout"
    Layout.fillWidth: true

    GridLayout {
        id: gridLayout
        rows: 3
        flow: GridLayout.TopToBottom
        anchors.fill: parent
        Label { text: "Line 1" }
        Label { text: "Line 2" }
        Label { text: "Line 3" }

        TextField { }
        TextField { }
        TextField { }

        TextArea {
            text: "This widget spans over three rows in the GridLayout.\n"
                  + "All items in the GridLayout are implicitly positioned from top to bottom."
            Layout.rowSpan: 3
            Layout.fillHeight: true
            Layout.fillWidth: true
        }
    }
}

위의 코드 조각은 '기본 레이아웃(Basic Layouts )' 예제에서 발췌한 것입니다. 이 코드 조각은 레이아웃에 다양한 필드와 항목을 추가하는 과정이 얼마나 간단한지 보여줍니다. ' GridLayout '의 크기는 조정할 수 있으며, 다양한 속성을 통해 형식을 사용자 정의할 수 있습니다.

레이아웃 유형에 대한 자세한 내용은 다음을 참조하십시오:

참고: Qt Quick Layouts Qt 5.1에서 도입되었으며 다음이 필요합니다. Qt Quick 2.1이 필요합니다.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.