|
你好 下边是我写的测试代码,执行环境:vs2013+qt5.5.1 没有问题
- class testObject: public QGraphicsObject
- {
- public:
- testObject() :QGraphicsObject(){}
- ~testObject(){}
- protected:
- virtual void paint(QPainter *painter
- , const QStyleOptionGraphicsItem *option
- , QWidget *widget /* = Q_NULLPTR */)
- {
- painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
- }
- virtual QRectF boundingRect() const
- {
- qreal penWidth = 1;
- return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
- 20 + penWidth, 20 + penWidth);
- // return QRectF(0, 0, 100, 100);
- }
- };
- graphics::graphics(QWidget *parent)
- : QWidget(parent)
- {
- ui.setupUi(this);
- QGraphicsScene * scene = new QGraphicsScene;
- testObject * test = new testObject;
- scene->addItem(test);
- ui.graphicsView->setScene(scene);
- QPropertyAnimation * animation = new QPropertyAnimation(test, "scale");
- animation->setDuration(1000);
- animation->setStartValue(1);
- animation->setEndValue(0.1);
- animation->start();
- }
- graphics::~graphics()
- {
- }
复制代码 |
|