#include <QtGui>
#include <QPropertyAnimation>
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos
) public:
setPen(pen);
setBrush(brush);
}
};
#include "main.moc"
int main(int argc, char **argv){
view.setAttribute(Qt::WA_TranslucentBackground);
view.viewport()->setAttribute(Qt::WA_TranslucentBackground);
view.setScene(&scene);
RectItem
*rect
= new RectItem
(QRectF(0,
0,
200,
100),
QPen(Qt
::red), Qt
::blue);
scene.addItem(rect);
QPropertyAnimation *anim = new QPropertyAnimation(rect, "pos");
anim->setDuration(10000);
anim->setStartValue(scene.sceneRect().topLeft());
anim->setEndValue(scene.sceneRect().bottomRight());
anim->start();
view.show();
return app.exec();
}
#include <QtGui>
#include <QPropertyAnimation>
class RectItem : public QObject, public QGraphicsRectItem {
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
public:
RectItem(const QRectF &rect, const QPen &pen, const QBrush &brush) : QObject(), QGraphicsRectItem(rect){
setPen(pen);
setBrush(brush);
}
};
#include "main.moc"
int main(int argc, char **argv){
QApplication app(argc, argv);
QGraphicsView view;
view.setAttribute(Qt::WA_TranslucentBackground);
view.viewport()->setAttribute(Qt::WA_TranslucentBackground);
QGraphicsScene scene(QRectF(0,0,1000,800));
view.setScene(&scene);
RectItem *rect = new RectItem(QRectF(0,0,200,100), QPen(Qt::red), Qt::blue);
scene.addItem(rect);
QPropertyAnimation *anim = new QPropertyAnimation(rect, "pos");
anim->setDuration(10000);
anim->setStartValue(scene.sceneRect().topLeft());
anim->setEndValue(scene.sceneRect().bottomRight());
anim->start();
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks