#include <QtGui>
Q_OBJECT
public:
Q_PROPERTY(QPointF pos WRITE setPos READ pos
)
}
};
int main(int argc , char **argv){
view.
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.setScene(&scene);
scene.setSceneRect(0,0,1280,1024);
Rect* rect = new Rect();
rect->setRect(0,0,500,500);
scene.addItem(rect);
rect->setBrush(brush);
QPropertyAnimation anim(rect,"pos");
int duration = 5000;
anim.
setKeyValueAt(0.25 ,
QPointF(500,
0) );
anim.
setKeyValueAt(0.5 ,
QPointF(500,
500) );
anim.
setKeyValueAt(0.75 ,
QPointF(0,
500) );
anim.setDuration(duration);
anim.setLoopCount(-1);
anim.start();
view.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
class Rect : public QObject , public QGraphicsRectItem {
Q_OBJECT
public:
Q_PROPERTY(QPointF pos WRITE setPos READ pos)
Rect(QGraphicsItem* item = 0) : QObject(),QGraphicsRectItem(item) {
}
};
int main(int argc , char **argv){
QApplication app(argc,argv);
QGraphicsView view;
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.setCacheMode(QGraphicsView::CacheBackground);
view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
QGraphicsScene scene;
view.setScene(&scene);
scene.setSceneRect(0,0,1280,1024);
Rect* rect = new Rect();
rect->setRect(0,0,500,500);
scene.addItem(rect);
QBrush brush(Qt::red);
rect->setBrush(brush);
rect->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
QPropertyAnimation anim(rect,"pos");
int duration = 5000;
anim.setStartValue(QPointF(0,0));
anim.setKeyValueAt(0.25 , QPointF(500,0) );
anim.setKeyValueAt(0.5 , QPointF(500,500) );
anim.setKeyValueAt(0.75 , QPointF(0,500) );
anim.setEndValue(QPointF(0,0));
anim.setDuration(duration);
anim.setLoopCount(-1);
anim.start();
view.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks