Behavior QML Type

속성 변경에 대한 기본 애니메이션을 정의합니다. 더 보기...

Import Statement: import QtQuick

속성

상세 설명

비헤이비어는 특정 속성 값이 변경될 때마다 적용될 기본 애니메이션을 정의합니다.

예를 들어 다음 비헤이비어는 Rectanglewidth 값이 변경될 때마다 실행될 NumberAnimation 을 정의합니다. MouseArea 을 클릭하면 width 이 변경되어 동작의 애니메이션이 트리거됩니다:

import QtQuick

Rectangle {
    id: rect
    width: 100; height: 100
    color: "red"

    Behavior on width {
        NumberAnimation { duration: 1000 }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: rect.width = 50
    }
}

프로퍼티에는 비헤이비어가 두 개 이상 할당될 수 없습니다. 동작 내에서 여러 애니메이션을 제공하려면 ParallelAnimation 또는 SequentialAnimation 을 사용하세요.

상태 변경에 동작과 동일한 속성과 일치하는 Transition 이 있는 경우 Transition 애니메이션이 해당 상태 변경에 대한 동작을 재정의합니다. 동작을 사용하여 상태 변경에 애니메이션을 적용하는 방법에 대한 일반적인 조언은 상태와 함께 Qt Quick 동작 사용하기를 참조하세요.

또한 Qt Quick 의 애니메이션 및 전환, 동작 예제Qt Qml.

프로퍼티 문서

animation : Animation [default]

이 프로퍼티는 동작이 트리거될 때 실행할 애니메이션을 보유합니다.


enabled : bool

이 프로퍼티에는 추적된 프로퍼티의 값이 변경될 때 동작이 트리거될지 여부가 저장됩니다.

기본적으로 비헤이비어는 활성화되어 있습니다.


targetProperty group

targetProperty.name : string [read-only, since QtQuick 2.15]

targetProperty.object : QtObject [read-only, since QtQuick 2.15]

속성설명
name이 프로퍼티는 이 비헤이비어에 의해 제어되는 프로퍼티의 이름을 보유합니다.
object이 프로퍼티는 이 비헤이비어에 의해 제어되는 프로퍼티의 객체를 보유합니다.

이 프로퍼티는 제어되는 프로퍼티의 이름 또는 객체를 기반으로 사용자 정의 동작을 정의하는 데 사용할 수 있습니다.

다음 예시는 제어하는 프로퍼티가 변경될 때 대상 오브젝트가 페이드 아웃되고 페이드 인하는 동작을 정의합니다:

// FadeBehavior.qml
import QtQuick 2.15

Behavior {
    id: root
    property Item fadeTarget: targetProperty.object
    SequentialAnimation {
        NumberAnimation {
            target: root.fadeTarget
            property: "opacity"
            to: 0
            easing.type: Easing.InQuad
        }
        PropertyAction { } // actually change the controlled property between the 2 other animations
        NumberAnimation {
            target: root.fadeTarget
            property: "opacity"
            to: 1
            easing.type: Easing.OutQuad
        }
    }
}

텍스트가 변경될 때 애니메이션을 적용하는 데 사용할 수 있습니다:

import QtQuick 2.15

Text {
    id: root
    property int counter
    text: counter
    FadeBehavior on text {}
    Timer {
        running: true
        repeat: true
        interval: 1000
        onTriggered: ++root.counter
    }
}

이 QML 프로퍼티는 QtQuick 2.15에 도입되었습니다.


targetValue : Variant [read-only, since QtQuick 2.13]

이 프로퍼티는 비헤이비어에 의해 제어되는 프로퍼티의 목표 값을 보유합니다. 이 값은 애니메이션이 시작되기 전에 동작에 의해 설정됩니다.

이 속성은 QtQuick 2.13에 도입되었습니다.


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