PropertyAction for AnchorChanges



  • Hi all,

    I have an Item with some states, and some PropertyChanges. Also, i've defined a transition between states, with a ParallelAnimation.
    Inside of the ParallelAnimation, i've put some PropertyAnimation and some PropertyActions, because i want some property values to be changed at the beginning of the transition, without any animation.

    My problem is about an AnchorChange element in the state. I want the anchor to be changed also at the beginning of the transition, without animation. I tried to use a PropertyAction, but it doesn't work with the anchor.

    I would like to know if PropertyAction can be used with anchors, because i cannot find any information about that in the documentation. It seems that the PropertyAction elment can only be used with properties configured in the PropertyChanges elements.

    Many thanks in advance



  • Hi again:

    I've prepared a testing qml to show the issue:

    Window {
        visible: true;width: 360;height: 360
    
        MouseArea{
            anchors.fill: parent
            onClicked: container.state = (container.state=="estado1"?"estado2":"estado1")
        }
    
        Rectangle {
            id: container
            anchors.fill: parent
            color: "red"
            state: "estado1"
            onStateChanged:console.log("state -> "+state)
    
            Rectangle {
                id: prueba
                anchors.left: parent.left
                height: 100
                color: "blue"
                onWidthChanged:console.log("width -> "+width)
                onHeightChanged:console.log("height -> "+height)
                onOpacityChanged:console.log("opacity -> "+opacity)
                onYChanged: console.log("coordY -> "+y)
    
            }
            states: [
                State {
                    name: "estado1"
                    PropertyChanges {
                        target: prueba
                        width: 300
                        opacity: 1
                    }
                    AnchorChanges {
                        target: prueba
                        anchors.bottom: container.bottom
                    }
                },
                State {
                    name: "estado2"
                    PropertyChanges {
                        target: prueba
                        width: 50
                        opacity: 0.5
                    }
                    AnchorChanges {
                        target: prueba
                        anchors.top: container.top
                    }
                }
            ]
            transitions:[
                Transition {
                    ParallelAnimation {
                        PropertyAnimation {
                            target: prueba
                            properties: "width"
                            duration: 3000
                        }
                        PropertyAction {
                            target: prueba
                            property: "opacity"
                        }
                        /*PropertyAction {
                            target: prueba
                            property: "anchors.top" //doesn't work
                            //property: "anchors" //doesn't work neither
                        }*/
                        AnchorAnimation {
                            //works, but doesn't seem to be the most
                            //elegant solution to the problem
                            duration: 0
                        }
                    }
                }
            ]
        }
    }
    

    If you run this example as is, you can see that the anchor change is performed at the beginning of the transition, because of the animation with duration=0. I think this is not very correct, since you really don't need an animation for that.

    For PropertyChanges, you can use the PropertyAction, as can be seen for the opacity change in the example. But, the PropertyAction doesn't work with the AnchorChange. I don't know if this is because of the sintax, or really PropertyAction cannot be used in this situation. I would like to know what is the best and more correct approach to do that.

    Thanks for your patience


Log in to reply
 

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