[Qt-qml] Weirdness with Behaviors

Tico Ballagas ballagas at gmail.com
Fri Sep 17 08:41:26 CEST 2010


I'm seeing some weirdness with Behaviors.  I created the following example to demonstrate what is happening.  Basically, I'm trying to snap rect back to it's original position after the mouse is released.  The behavior works once, but then stops working. 

import Qt 4.7
Rectangle {
    id:window
    width: 640
    height: 480
    Rectangle{
        id:rect
        color: "red"
        width:100
        height:100
        Behavior on x {
            NumberAnimation { duration: 200 }
        }
    }
    MouseArea{
        anchors.fill: rect
        drag.target: rect
        drag.axis: Drag.XAxis
        drag.minimumX: 0
        drag.maximumX: window.width - rect.width
        onReleased:{
            rect.x = 0
        }
    }
}


Interestingly, if I add the following to the MouseArea, it seems to work correctly.

onPositionChanged:{
	rect.x = rect.x
}

It seems that the Behavior only works if the value of rect.x is changed, but doesn't seem to recognize the drag as a change in rect.x.  Is this expected behavior?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100916/1f8ca65e/attachment.html 


More information about the Qt-qml mailing list