Behavior QML Type
Définit une animation par défaut pour un changement de propriété. Plus d'informations...
| Import Statement: | import QtQuick |
Propriétés
- 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)
Description détaillée
Un comportement définit l'animation par défaut à appliquer chaque fois que la valeur d'une propriété particulière change.
Par exemple, le comportement suivant définit une animation NumberAnimation à exécuter chaque fois que la valeur width de Rectangle change. Lorsque l'on clique sur MouseArea, la valeur de width est modifiée, ce qui déclenche l'animation du comportement :
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 } }
Notez qu'une propriété ne peut pas avoir plus d'un comportement assigné. Pour fournir plusieurs animations au sein d'un comportement, utilisez ParallelAnimation ou SequentialAnimation.
Si un changement d'état possède un Transition qui correspond à la même propriété qu'un comportement, l'animation Transition remplace le comportement pour ce changement d'état. Pour des conseils généraux sur l'utilisation des comportements pour animer les changements d'état, voir Utilisation des comportements Qt Quick avec les états.
Voir également Animation et transitions dans Qt Quick, Exemple de comportement et Qt Qml.
Documentation sur les propriétés
animation : Animation [default]
Cette propriété contient l'animation à exécuter lorsque le comportement est déclenché.
enabled : bool
Cette propriété indique si le comportement doit être déclenché lorsque la valeur de la propriété suivie change.
Par défaut, un comportement est activé.
targetProperty group
targetProperty.name : string [read-only, since QtQuick 2.15]
targetProperty.object : QtObject [read-only, since QtQuick 2.15]
| Propriété | Description de la propriété |
|---|---|
| nom | Cette propriété contient le nom de la propriété contrôlée par ce comportement. |
| objet | Cette propriété contient l'objet de la propriété contrôlée par ce comportement. |
Cette propriété peut être utilisée pour définir des comportements personnalisés basés sur le nom ou l'objet de la propriété contrôlée.
L'exemple suivant définit un comportement dont l'objet cible s'éteint et s'allume en fondu lorsque la propriété qu'il contrôle change :
// 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 } } }
Ce comportement peut être utilisé pour animer un texte lorsqu'il change :
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 } }
Ces propriétés ont été introduites dans QtQuick 2.15.
targetValue : Variant [read-only, since QtQuick 2.13]
Cette propriété contient la valeur cible de la propriété contrôlée par le Comportement. Cette valeur est définie par le Comportement avant que l'animation ne soit lancée.
Cette propriété a été introduite dans 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.