이 페이지에서

애니메이션

Qt Quick 속성에 애니메이션을 적용할 수 있습니다. 속성에 애니메이션을 적용하면 속성 값이 대상 값으로 즉시 변경되는 대신 중간 값을 거쳐 이동할 수 있습니다. 항목의 위치를 애니메이션 처리하려면, 항목의 위치를 제어하는 속성(예: x 및 y)에 애니메이션을 적용하여 항목이 대상 위치로 이동하는 과정에서 매 프레임마다 위치가 변경되도록 할 수 있습니다.

유동적인 UI

QML은 유동적인 UI를 쉽게 만들 수 있도록 설계되었습니다. 유동적인 UI란 UI 컴포넌트가 갑자기 나타나거나 사라지거나 급격하게 이동하는 대신 애니메이션을 통해 부드럽게 움직이는 사용자 인터페이스를 말합니다. ` Qt Quick `는 UI 컴포넌트가 새로운 위치에 즉시 나타나는 대신 애니메이션을 통해 이동하도록 하는 두 가지 간단한 방법을 제공합니다.

상태와 전환

Qt Quick State 객체에서 다양한 UI 상태를 선언할 수 있습니다. 이러한 상태는 기본 상태로부터의 속성 변경으로 구성되며, UI 로직을 체계적으로 구성하는 데 유용한 방법이 될 수 있습니다. 전환(Transitions)은 항목에 연결하여 상태 변경으로 인해 속성이 변경될 때 어떻게 애니메이션이 적용될지 정의할 수 있는 객체입니다.

항목의 상태와 전환은 ` Item::states ` 및 ` Item::transitions ` 속성을 사용하여 선언할 수 있습니다. 상태는 항목(일반적으로 컴포넌트의 루트 항목)의 `states` 목록 속성 내에서 선언됩니다. 동일한 항목에 정의된 전환은 상태 변화 시 발생하는 변경 사항을 애니메이션으로 표현하는 데 사용됩니다. 다음은 그 예시입니다.

Item {
    id: container
    width: 320
    height: 120

    Rectangle {
        id: rect
        color: "red"
        width: 120
        height: 120

        TapHandler {
            onTapped: container.state === '' ? container.state = 'other' : container.state = ''
        }
    }
    states: [
        // This adds a second state to the container where the rectangle is farther to the right

        State { name: "other"

            PropertyChanges {
                target: rect
                x: 200
            }
        }
    ]
    transitions: [
        // This adds a transition that defaults to applying to all state changes

        Transition {

            // This applies a default NumberAnimation to any changes a state change makes to x or y properties
            NumberAnimation { properties: "x,y" }
        }
    ]
}

속성 변경에 애니메이션 적용하기.

비헤이비어(Behaviors)를 사용하면 속성이 변경될 때 적용할 애니메이션을 지정할 수 있습니다. 이 애니메이션은 변경의 원인과 관계없이 모든 변경 사항에 적용됩니다. 다음 예제는 비헤이비어를 사용하여 버튼이 화면을 이동하는 애니메이션을 구현합니다.

Item {
    width: 320
    height: 120

    Rectangle {
        color: "green"
        width: 120
        height: 120

        // This is the behavior, and it applies a NumberAnimation to any attempt to set the x property
        Behavior on x {

            NumberAnimation {
                //This specifies how long the animation takes
                duration: 600
                //This selects an easing curve to interpolate with, the default is Easing.Linear
                easing.type: Easing.OutBounce
            }
        }

        TapHandler {
            onTapped: parent.x == 0 ? parent.x = 200 : parent.x = 0
        }
    }
}

기타 애니메이션

모든 애니메이션이 반드시 특정 속성이나 상태에 연결되어야 하는 것은 아닙니다. 보다 일반적인 방식으로 애니메이션을 생성하고, 애니메이션 내에서 대상 항목과 속성을 지정할 수도 있습니다. 다음은 이를 수행하는 다양한 방법의 예시입니다:

Item {
    width: 320
    height: 120

    Rectangle {
        color: "blue"
        width: 120
        height: 120

        // By setting this SequentialAnimation on x, it and animations within it will automatically animate
        // the x property of this element
        SequentialAnimation on x {
            id: xAnim
            // Animations on properties start running by default
            running: false
            loops: Animation.Infinite // The animation is set to loop indefinitely
            NumberAnimation { from: 0; to: 200; duration: 500; easing.type: Easing.InOutQuad }
            NumberAnimation { from: 200; to: 0; duration: 500; easing.type: Easing.InOutQuad }
            PauseAnimation { duration: 250 } // This puts a bit of time between the loop
        }

        TapHandler {
            // The animation starts running when you click within the rectangle
            onTapped: xAnim.running = true
        }
    }
}
Item {
    width: 320
    height: 120

    Rectangle {
        id: rectangle
        color: "yellow"
        width: 120
        height: 120

        TapHandler {
            // The animation starts running when you click within the rectangle
            onTapped: anim.running = true;
        }
    }

    // This animation specifically targets the Rectangle's properties to animate
    SequentialAnimation {
        id: anim
        // Animations on their own are not running by default
        // The default number of loops is one, restart the animation to see it again

        NumberAnimation { target: rectangle; property: "x"; from: 0; to: 200; duration: 500 }

        NumberAnimation { target: rectangle; property: "x"; from: 200; to: 0; duration: 500 }
    }
}

빨강, 초록, 파랑, 노랑 사각형이 엇갈린 위치에 배치되어 있다

애니메이션에 대한 자세한 내용은 ‘ Qt Quick 의 중요한 개념 - 상태, 전환 및 애니메이션’ 페이지에서 확인할 수 있습니다.

© 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.