[Qt-jambi-interest] Restart SVG Animation

Gunnar Sletta gunnar at trolltech.com
Tue Aug 12 08:35:49 CEST 2008


Dimitri Frederickx wrote:
> Gunnar Sletta <gunnar at trolltech.com> wrote:
>  
>> Dimitri Frederickx wrote:
>>> Hi,
>>>
>>> I'm creating a QGraphicsSvgItem to display an svg file with 
>>> animations. When I open the item, the animation automatically starts.
>>>
>>> Is there a way to stop the animation and start it back? And is there a 
>>> method for resetting the animation (to the first frame)?
>> Hi Dimitri,
>>
>> You can access the item's svg renderer using 
>> QGraphicsSvgItem::renderer(). Using the renderer you can 
>> setCurrentFrame() which should give you what you want.
>>
>> best regards,
>> Gunnar
>>
> 
> Oops, I've overlooked that method. It seems that in the Qt 4.4 documentation 
> (http://doc.trolltech.com/4.4/qsvgrenderer.html) this method is not documented.

Why do you look at the C++ documentation? The proper docs are located at:
http://doc.trolltech.com/qtjambi-4.4/html/com/trolltech/qt/svg/QSvgRenderer.html
http://doc.trolltech.com/qtjambi-4.4/html/com/trolltech/qt/svg/QSvgRenderer.html#setCurrentFrame(int)

Anyway... In C++, currentFrame is a property and is documented in the 
property section:
http://doc.trolltech.com/main-snapshot/qsvgrenderer.html#framesPerSecond-prop

> Is there also a possibility to stop/pauze/start the animation?

There is no setAnimated(), unfortunately, so you cannot stop and restart 
the animation, as far as I can see.

Perhaps the best option in this case is to subclass the svg item, and 
control the animation based on your own timer and using 
setCurrentFrame() in addition to framePerSecond to get the right speed?


best regards,
Gunnar



More information about the Qt-jambi-interest mailing list