본문 바로가기

Programming/QT&QML

[QT, QML] QML Component anchor

728x90
반응형
# QT Version : 5.12 
# QT Creatpr Version : 4.11
# Project name : anchor

My_Github_Link

 

jungmonster/qt_study_project

Qt projects for my study. Contribute to jungmonster/qt_study_project development by creating an account on GitHub.

github.com

qml 에서 Component 위치를 잡을 때 x, y 값으로 할 도 있지만 component의 기준으로 위치를 잡을 수 있다.

QT Document

위와 같이 값을 표현할 수 있는데 추가적으로 anchor.fill도 사용할 수 있다 anchor.fill을 사용하면 부모 컴포넌트 영역과 같아진다.

Component에서 사용 하는 방법은 anchors.xxx로 사용하는 방법과 대괄호로 속성을 지정 할 수 있다.

1번 방법

        Rectangle{
            id : r3
            width: 100
            height: 100
            anchors.bottom: r2.verticalCenter
            anchors.left : r2.right
            color: "blue"
            border.color: "black"
        }

2번 방법

Rectangle{
            id : r4
            width: 100
            height: 100
            anchors{
                verticalCenter: parent.verticalCenter
                horizontalCenter: parent.horizontalCenter
            }

            color: "white"
            border.color: "black"
        }

결과물

반응형