Animation of QGraphicsItem in QGraphicsView
I want to make an animation with QGraphicsItem. I know it is possible with QGraphicsItemAnimation, but I want to join more animations with QSequentialAnimationGroup. In order to do this, child animations have to inherit QAbstractAnimation. In docs, there is an example how to do this with QPropertyAnimation. The key to victory is macro Q_PROPERTY as explained here: http://doc.trolltech.com/solutions/4...view-framework.
I tried to implement. It compiled succesfully, but in runtime, when creating QPropertyAnimation, the error appeared:
QPropertyAnimation: you're trying to animate a non-existing property setPos of your QObject.
But it is declared in the macro, so where is the problem?
Code:
#ifndef CARDITEM_H
#define CARDITEM_H
class CardItem;
#include <QGraphicsItem>
#include <QMouseEvent>
#include <QDebug>
#include "deskview.h"
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos
) public:
CardItem();
int cid;
};
#endif // CARDITEM_H
Code:
...
CardItem* ci = new CardItem();
ci->setPixmap(rub);
ci->setPos(-100,150);
ci->setZValue(10);
graphicsView->scene()->addItem(ci);
QPropertyAnimation an(ci,"setPos");
...
Re: Animation of QGraphicsItem in QGraphicsView
Quote:
Originally Posted by
mirelon
Code:
QPropertyAnimation an(ci,"setPos");
You must use the name of the property!
Code:
QPropertyAnimation an(ci,"pos");
Re: Animation of QGraphicsItem in QGraphicsView
Thank you very much, now I am going on with my project. But another question arises. When some animation is going near the border of graphicsView, it automatically moves the whole scene and the scrollbars appear.
I searched for it, but I dont have correct keywords for it, i think it should be some property of graphics view. I want something like the coordinate system in graphics view is fixed, so it dont move on its own.
Re: Animation of QGraphicsItem in QGraphicsView
Then you have to set a sceen rect by your own. Then Qt wont adjust the size automatically. And you might want to positioning the scene on the top rather than in the middle.
Re: Animation of QGraphicsItem in QGraphicsView
Ok, i managed to do it...but not while i want to enable resizing of the window.
I have:
main window
central widget (vertical layout, so i can set size policy)
graphics view
graphics scene
and when i resize main window, the graphics view should be also resized
it can be done with size policy "expanding"
but i also want to have graphics scene fixed 800*600 (i have hard-coded positions of animations in it, so it must be this size), so resizing will zoom the scene.
how can i do that?