Behavior QML Type
Define una animación por defecto para un cambio de propiedad. Más...
| Import Statement: | import QtQuick |
Propiedades
- animation : Animation
- enabled : bool
- targetProperty
(since QtQuick 2.15)- targetProperty.name : string
(since QtQuick 2.15) - targetProperty.object : QtObject
(since QtQuick 2.15)
- targetProperty.name : string
- targetValue : Variant
(since QtQuick 2.13)
Descripción detallada
Un comportamiento define la animación predeterminada que se aplicará cuando cambie el valor de una propiedad determinada.
Por ejemplo, el siguiente Comportamiento define un NumberAnimation que se ejecutará siempre que cambie el valor de Rectangle's width. Cuando se hace clic en MouseArea, el valor de width cambia, activando la animación del comportamiento:
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 } }
Tenga en cuenta que una propiedad no puede tener más de un comportamiento asignado. Para proporcionar múltiples animaciones dentro de un Comportamiento, utilice ParallelAnimation o SequentialAnimation.
Si un cambio de estado tiene un Transition que coincide con la misma propiedad que un Comportamiento, la animación Transition anula el Comportamiento para ese cambio de estado. Para obtener consejos generales sobre el uso de comportamientos para animar cambios de estado, consulte Uso de comportamientos con estados en Qt Quick .
Véase también Animación y transiciones en Qt Quick, Ejemplo de comportamiento, y Qt Qml.
Documentación de Propiedades
animation : Animation [default]
Esta propiedad contiene la animación que se ejecutará cuando se active el comportamiento.
enabled : bool
Esta propiedad indica si el comportamiento se activará cuando la propiedad rastreada cambie de valor.
Por defecto se activa un Comportamiento.
targetProperty group
targetProperty.name : string [read-only, since QtQuick 2.15]
targetProperty.object : QtObject [read-only, since QtQuick 2.15]
| Propiedad | Descripción |
|---|---|
| nombre | Esta propiedad contiene el nombre de la propiedad que está siendo controlada por este Comportamiento. |
| objeto | Esta propiedad contiene el objeto de la propiedad controlada por este comportamiento. |
Esta propiedad puede utilizarse para definir comportamientos personalizados basados en el nombre o el objeto de la propiedad controlada.
El siguiente ejemplo define un comportamiento que se desvanece y se desvanece en su objeto de destino cuando la propiedad que controla cambia:
// 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 } } }
Esto se puede utilizar para animar un texto cuando cambia:
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 } }
Estas propiedades se introdujeron en QtQuick 2.15.
targetValue : Variant [read-only, since QtQuick 2.13]
Esta propiedad contiene el valor objetivo de la propiedad controlada por el Comportamiento. Este valor es establecido por el Comportamiento antes de que se inicie la animación.
Esta propiedad se introdujo en QtQuick 2.13.
© 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.