2013-01-16 25 views
0

我想停止动画这样的动画:停止在非root动画节点

Behavior on x { 
    NumberAnimation { 
     id: animationElement 
     duration: 100 
    } 
} 
    ... 
if (something) 
{ 
    animationElement.stop() 
} 

但是这个代码给我的错误,即停止()不能在非root动画节点使用。 这可能是从外面停止动画?

回答

1

这对我工作得很好:

import QtQuick 1.0 

Rectangle 
{ 
    color: "grey" 
    width: 800 
    height: 800 

    NumberAnimation on width { id: animationElementw ; from: 800; to: 500; duration: 8500 } 
    NumberAnimation on height { id: animationElementH ; from: 800; to: 500; duration: 8500 } 

    MouseArea 
    { 
     anchors.fill: parent 
     onClicked: 
     { 
      animationElementw.stop() 
      animationElementH.stop() 
     } 
    } 

    Text 
    { 
     id: name 
     anchors.centerIn: parent 
     text: "Click me to stop shrinking animation!!!" 
     color: "white" 
     font.pixelSize: 25 
    } 
}