找回密码
 立即注册
收起左侧

从QGraphicsObject继承的类,用QPropertyAnimation怎么实现缩放动...

4
回复
7147
查看
[复制链接]
累计签到:2 天
连续签到:1 天
来源: 2016-9-27 23:04:00 显示全部楼层 |阅读模式
1Qter豆
如题:
我从QGraphicsObject继承类之后,自定义一个图形,然后怎么样才能用QPropertyAnimation实现缩放动画呢?

回复

使用道具 举报

累计签到:2 天
连续签到:1 天
2016-9-27 23:04:40 显示全部楼层
我是这么写的,结果发现不动啊
QPropertyAnimation *animation = new QPropertyAnimation(pStartPos, "scale");
    animation->setDuration(1000);
    animation->setStartValue(1);
    animation->setEndValue(0.1);
    animation->start();
回复

使用道具 举报

累计签到:4 天
连续签到:1 天
2016-10-6 12:37:51 显示全部楼层
你好  下边是我写的测试代码,执行环境:vs2013+qt5.5.1  没有问题

  1. class testObject: public QGraphicsObject
  2. {
  3. public:
  4.         testObject() :QGraphicsObject(){}
  5.         ~testObject(){}

  6. protected:
  7.         virtual void paint(QPainter *painter
  8.                 , const QStyleOptionGraphicsItem *option
  9.                 , QWidget *widget /* = Q_NULLPTR */)
  10.         {
  11.                 painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
  12.         }
  13.         virtual QRectF boundingRect() const
  14.         {
  15.                 qreal penWidth = 1;
  16.                 return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
  17.                         20 + penWidth, 20 + penWidth);
  18.         //        return QRectF(0, 0, 100, 100);
  19.         }
  20. };

  21. graphics::graphics(QWidget *parent)
  22.         : QWidget(parent)
  23. {
  24.         ui.setupUi(this);

  25.         QGraphicsScene * scene = new QGraphicsScene;
  26.         testObject * test = new testObject;
  27.         scene->addItem(test);

  28.         ui.graphicsView->setScene(scene);


  29.         QPropertyAnimation * animation = new QPropertyAnimation(test, "scale");
  30.         animation->setDuration(1000);
  31.         animation->setStartValue(1);
  32.         animation->setEndValue(0.1);
  33.         animation->start();
  34. }

  35. graphics::~graphics()
  36. {

  37. }
复制代码
回复

使用道具 举报

累计签到:4 天
连续签到:1 天
2016-10-6 12:38:39 显示全部楼层
如果需要demo,我可以发给你
回复

使用道具 举报

累计签到:12 天
连续签到:1 天
2016-12-20 08:55:33 显示全部楼层
    QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "geometry");

    QDesktopWidget *pDesktopWidget = QApplication::desktop();
    int x = (pDesktopWidget->availableGeometry().width() - width()) / 2;
    int y = (pDesktopWidget->availableGeometry().height() - height()) / 2;

    pAnimation->setDuration(1000);
    pAnimation->setStartValue(QRect(x, y, 0, 0));
    pAnimation->setEndValue(QRect(0, 0, pDesktopWidget->availableGeometry().width(), pDesktopWidget->availableGeometry().height()));
    pAnimation->setEasingCurve(QEasingCurve::OutCirc);
    pAnimation->start(QAbstractAnimation:eleteWhenStopped);
    connect(pAnimation,SIGNAL(finished()),this,SLOT(showFullScreen()));
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了