import QtQml 2.15 import QtQuick 2.15 // This Behavior components allow to do VisibleBehavior on visible {} and fades the opacity of an Item whenever its visibility changes // with a pair of targetObject and targetProperty name Behavior { id: root property QtObject targetObject // I'd like that Behavior supplies this property so that I don't have to define it in my user code property string targetPropertyName SequentialAnimation { NumberAnimation { target: root.targetObject // if I don't specify a target, the defaultTarget's target is not used since I specify a property (cf. QQuickPropertyAnimation::createTransitionActions hasSelector) property: "opacity" duration: root.targetValue ? 0 : 200 to: 0 easing.type: Easing.InQuad } PropertyAction { } // this uses the defaultTarget set by the Behavior NumberAnimation { target: root.targetObject property: "opacity" duration: root.targetValue ? 200 : 0 to: 1 easing.type: Easing.OutQuad } } } // with a single qqmlproperty property Behavior { id: root // property QQmlProperty targetProperty // I'd like that Behavior supplies this property so that I don't have to define it in my user code SequentialAnimation { NumberAnimation { target: root.targetProperty.object // if I don't specify a target, the defaultTarget's target is not used since I specify a property (cf. QQuickPropertyAnimation::createTransitionActions hasSelector) property: "opacity" duration: root.targetValue ? 0 : 200 to: 0 easing.type: Easing.InQuad } PropertyAction { } // this uses the defaultTarget set by the Behavior NumberAnimation { target: root.targetProperty.object property: "opacity" duration: root.targetValue ? 200 : 0 to: 1 easing.type: Easing.OutQuad } } }