#include <QtGui>
class Item : public QGraphicsObject {
Q_OBJECT
Q_PROPERTY(qreal size READ size WRITE setSize)
public:
setSize(10.0);
}
void setSize(qreal s) {
if(m_rect.width()==s) return;
m_rect
= QRectF(-s
/2,
-s
/2, s, s
);
prepareGeometryChange();
}
qreal size() const { return m_rect.width(); }
return m_rect;
}
painter->setBrush(Qt::red);
painter->drawEllipse(boundingRect());
}
private:
};
#include "main.moc"
int main(int argc, char **argv){
qsrand
(QDateTime::currentDateTime().
toTime_t());
QParallelAnimationGroup *animGrp = new QParallelAnimationGroup(&scene);
animGrp->setLoopCount(-1);
for(int i=0;i<10;++i) {
Item *item = new Item;
scene.addItem(item);
item->setPos(qrand() % 400, qrand()%400);
QPropertyAnimation *anim = new QPropertyAnimation(item, "size", animGrp);
animGrp->addAnimation(anim);
anim->setStartValue(qrand()%30);
anim->setEndValue(40+qrand()%50);
anim->setEasingCurve(QEasingCurve::Type(qrand()%41));
anim->setDuration(250*(qrand()%10));
}
view.setScene(&scene);
view.show();
view.
setRenderHint(QPainter::Antialiasing);
animGrp->start();
return app.exec();
}
#include <QtGui>
class Item : public QGraphicsObject {
Q_OBJECT
Q_PROPERTY(qreal size READ size WRITE setSize)
public:
Item(QGraphicsItem *parent = 0) : QGraphicsObject(parent) {
setSize(10.0);
}
void setSize(qreal s) {
if(m_rect.width()==s) return;
m_rect = QRectF(-s/2,-s/2, s, s);
prepareGeometryChange();
}
qreal size() const { return m_rect.width(); }
QRectF boundingRect() const {
return m_rect;
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) {
painter->setBrush(Qt::red);
painter->drawEllipse(boundingRect());
}
private:
QRectF m_rect;
};
#include "main.moc"
int main(int argc, char **argv){
QApplication app(argc, argv);
qsrand(QDateTime::currentDateTime().toTime_t());
QGraphicsScene scene;
QGraphicsView view;
QParallelAnimationGroup *animGrp = new QParallelAnimationGroup(&scene);
animGrp->setLoopCount(-1);
for(int i=0;i<10;++i) {
Item *item = new Item;
scene.addItem(item);
item->setPos(qrand() % 400, qrand()%400);
QPropertyAnimation *anim = new QPropertyAnimation(item, "size", animGrp);
animGrp->addAnimation(anim);
anim->setStartValue(qrand()%30);
anim->setEndValue(40+qrand()%50);
anim->setEasingCurve(QEasingCurve::Type(qrand()%41));
anim->setDuration(250*(qrand()%10));
}
view.setScene(&scene);
view.show();
view.setRenderHint(QPainter::Antialiasing);
animGrp->start();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks