2013-01-16 26 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 
    } 
}