#include <QtCore>#include <QtGui>class MyGraphicsEllipseItem : public QObject, public QGraphicsEllipseItem{ Q_OBJECT Q_PROPERTY(QBrush brush READ brush WRITE setBrush)public: MyGraphicsEllipseItem(const QRectF &rect) : QObject(), QGraphicsEllipseItem(rect) { setCacheMode(DeviceCoordinateCache); }};int main(int argc, char **argv){ QApplication app(argc, argv); QObject *ball = new MyGraphicsEllipseItem(QRectF(0, 0, 20, 20)); QPropertyAnimation animation(ball, "brush"); animation.setDuration(10000); animation.setKeyValueAt(0, QBrush(QColor(255,0,0))); animation.setKeyValueAt(0.8, QBrush(QColor(0,255,0))); animation.setKeyValueAt(1, QBrush(QColor(0,0,255))); QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0, 0, 220, 220); scene->addItem((QGraphicsItem*)ball); QGraphicsView *view = new QGraphicsView(scene); view->show(); return app.exec();}
#include <QtCore>#include <QtGui>class MyGraphicsEllipseItem : public QObject, public QGraphicsEllipseItem{ Q_OBJECT Q_PROPERTY(QBrush brush READ brush WRITE setBrush)public: MyGraphicsEllipseItem(const QRectF &rect) : QObject(), QGraphicsEllipseItem(rect) { setCacheMode(DeviceCoordinateCache); }};#include "main.moc"int main(int argc, char **argv){ QApplication app(argc, argv); MyGraphicsEllipseItem *ball = new MyGraphicsEllipseItem(QRectF(0, 0, 219, 219)); QPropertyAnimation animation(ball, "brush"); animation.setDuration(10000); animation.setKeyValueAt(0, QBrush(QColor(255,0,0))); animation.setKeyValueAt(0.8, QBrush(QColor(0,255,0))); animation.setKeyValueAt(1, QBrush(QColor(0,0,255))); QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0, 0, 220, 220); scene->addItem(ball); QGraphicsView *view = new QGraphicsView(scene); view->show(); animation.start(); return app.exec();}
#include <QtCore>#include <QtGui>class MyGraphicsEllipseItem : public QObject, public QGraphicsEllipseItem{ Q_OBJECT Q_PROPERTY(QColor color READ color WRITE setColor)public: MyGraphicsEllipseItem(const QRectF &rect) : QObject(), QGraphicsEllipseItem(rect) { setCacheMode(DeviceCoordinateCache); } QColor color() { qDebug() << "color()" << brush().color().name (); return brush().color(); } void setColor(QColor color) { qDebug() << "setColor()" << color.name (); setBrush(QBrush(color)); return; }};#include "main.moc"int main(int argc, char **argv){ QApplication app(argc, argv); MyGraphicsEllipseItem *ball = new MyGraphicsEllipseItem(QRectF(0, 0, 219, 219)); QPropertyAnimation animation(ball, "color"); animation.setDuration(10000); animation.setKeyValueAt(0, QColor(255,0,0)); animation.setKeyValueAt(0.8, QColor(0,255,0)); animation.setKeyValueAt(1, QColor(0,0,255)); QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0, 0, 220, 220); scene->addItem(ball); QGraphicsView *view = new QGraphicsView(scene); view->show(); animation.start(); return app.exec();}
#include <QtCore>#include <QtGui>class MyGraphicsEllipseItem : public QObject, public QGraphicsEllipseItem{ Q_OBJECT Q_PROPERTY(QBrush brush READ brush WRITE setBrush)public: MyGraphicsEllipseItem(const QRectF &rect) : QObject(), QGraphicsEllipseItem(rect) { setCacheMode(DeviceCoordinateCache); } QBrush brush() const{ qDebug() << "brush()" << QGraphicsEllipseItem::brush().color().name (); return QGraphicsEllipseItem::brush(); } void setBrush(const QBrush & brush) { qDebug() << "setBrush()" << brush.color().name (); QGraphicsEllipseItem::setBrush(brush); return; }};#include "main.moc"int main(int argc, char **argv){ QApplication app(argc, argv); MyGraphicsEllipseItem *ball = new MyGraphicsEllipseItem(QRectF(0, 0, 219, 219)); QPropertyAnimation animation(ball, "brush"); animation.setDuration(10000); animation.setKeyValueAt(0, QBrush(QColor(255,0,0))); animation.setKeyValueAt(0.8, QBrush(QColor(0,255,0))); animation.setKeyValueAt(1, QBrush(QColor(0,0,255))); QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0, 0, 220, 220); scene->addItem(ball); QGraphicsView *view = new QGraphicsView(scene); view->show(); animation.start(); return app.exec();}
C++ (Qt)void QAbstractGraphicsShapeItem::setBrush(const QBrush &brush){ Q_D(QAbstractGraphicsShapeItem); d->brush = brush; update();}
* Int * Double * Float * QLine * QLineF * QPoint * QSize * QSizeF * QRect * QRectF