Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Incrementing object values



  • Hello all,
    Im starting now with QML programming and have small beginner problem. I think I still simply do not get bindig thing :)

    What I want to do:
    In case of each pressing button I want to rotate some image by adding additional 45 degrees. But how I can increment the rotation value?
    @
    states: State{
    name: "move"
    PropertyChanges {
    target: buttonImage
    rotation: 45
    }
    }

    Currently I got smthg like:
    transitions: Transition {
    RotationAnimation{
    duration: 500
    direction: RotationAnimation.Clockwise
    }
    @

    If I set: rotation: buttonImage + 45 i got binding loop.

    Anybody knows?
    BR
    Thomas



  • rotation: rotation + 45
    Does it work?



  • Like I said before:
    QML Image: Binding loop detected for property "rotation"



  • Hi,

    @
    import QtQuick 2.1
    import QtQuick.Window 2.1
    import QtQuick.Controls 1.1

    Window {
    visible: true
    width: 360
    height: 400

    color: "grey"
    
    Button {
        id: myButton
    
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.topMargin: 20
    
        text: "rotate the box"
    
        onClicked: box.rotation = box.rotation + 45
    }
    
    // can be replaced by image
    Rectangle {
        id: box
    
        width: 100
        height: 100
    
        color: "blue"
    
        y: 200
        x: (parent.width - width) / 2
    
        Behavior on rotation {
            NumberAnimation { duration: 200 }
        }
    }
    

    }
    @



  • Ok, its working, but it doesn't animate the transform like when we use:
    @
    states: State{
    name: "move"
    PropertyChanges {
    target: buttonImage
    rotation: 45
    }
    }
    transitions: Transition {
    RotationAnimation{
    duration: 500
    direction: RotationAnimation.Clockwise
    }
    }
    @

    [edit: added missing coding tags SGaist]



  • Ahh sry :)
    My bad.
    You are right...
    Didnt read to the end :P


Log in to reply