[Solved] Listview's populate animation has ViewTransition.index of -1?



  • Basically what the topic says. I want to do an effect much like the google material design spec here http://www.google.com/design/spec/animation/meaningful-transitions.html#meaningful-transitions-hierarchical-timing . So I try to do something like this and it doesn't work.

    import QtQuick 2.4
    
    ListView {
        height: 600
        width: 800
        model: VisualItemModel {
            Rectangle { height: 50; width: 50; color: "red" }
            Rectangle { height: 50; width: 50; color: "blue" }
            Rectangle { height: 50; width: 50; color: "green" }
            Rectangle { height: 50; width: 50; color: "pink" }
            Rectangle { height: 50; width: 50; color: "purple" }
            Rectangle { height: 50; width: 50; color: "black" }
            Rectangle { height: 50; width: 50; color: "grey" }
        }
        populate: Transition {
            SequentialAnimation {
                ScriptAction { script: { console.log(ViewTransition.index); /* prints -1 */ } }
                PropertyAction { property: "scale"; value: 0; }
                PauseAnimation { duration: ViewTransition.index * 100 }
                NumberAnimation { duration: 500; properties: "scale"; from: 0; to: 1;}
            }
        }
    }
    

    Anyone got an idea?


  • Moderators

    @Buttink Specify an id to Transition and then access its property

    populate: Transition {
            id: transition
            SequentialAnimation {
                ScriptAction { script: { console.log(transition.ViewTransition.index); /* prints -1 */ } }
                PropertyAction { property: "scale"; value: 0; }
                PauseAnimation { duration: transition.ViewTransition.index * 100 }
                NumberAnimation { duration: 500; properties: "scale"; from: 0; to: 1;}
            }
        }
    


  • @p3c0 So I was just accessing a random attached property on the Action, not the ViewTransition attached property that was set by the grid view? Weird I was expecting a undefined if i accessed the wrong item.


  • Moderators

    @Buttink The attached properties are not always directly accessible by the children. It is documented here.
    It states:

    A common error is to assume that attached properties and signal handlers are directly accessible from the children of the object to which these attributes have been attached. This is not the case. The instance of the attaching type is only attached to specific objects, not to the object and all of its children.

    Check out the example provided there.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.