PDA

View Full Version : Using the animation framework with graphic items



technoViking
10th November 2009, 02:38
Hi guys, so I know its very easy to use the animation framework with widgets but I'm having issues using it with graphic items.

I know its possible because of this website:

http://pepper.troll.no/s60prereleases/betadoc/animation-overview.html

But for instance I'm trying to modify the setPositionAt() property to move the graphic items around the window (an animation) and I get an error saying geometry property isn't found in the graphic items property, I also tried "setPositionAt" still no luck.

ANy ideas what I'm doing wrong? What property do I need to maniuplate or tell the QPropertyAnimation that I want to maniuplate to allow movement of the graphics object? If I was hard coding it with a for loop, I would modify the setPositionAt(step,Qpoint) and it would work (infact I have done this) but I want to use the animation framework instead of hardcoding it.

This will work for a widget to make a widget animate around the screen:


QPushButton button("Animated Button");
button.show();

QPropertyAnimation animation(&button, "geometry");
animation.setDuration(10000);
animation.setStartValue(QRect(0, 0, 100, 30));
animation.setEndValue(QRect(250, 250, 100, 30));

animation.start();



But how can I do this with a graphics item rather than a widget? My class does inhert from a QObject.


The website says to do the following:
When you want to animate QGraphicsItems, you also use QPropertyAnimation. However, QGraphicsItem does not inherit QObject. A good solution is to subclass the graphics item you wish to animate. This class will then also inherit QObject. This way, QPropertyAnimation can be used for QGraphicsItems. The example below shows how this is done. Another possibility is to inherit QGraphicsWidget, which already is a QObject.


class Pixmap : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
...

As described in the previous section, we need to define properties that we wish to animate.