QT 设置QGraphicsItem动起来

QGraphicsLineItem *line;

    scene->addItem(line = new QGraphicsLineItem(QLineF(QPointF(0, 0), QPointF(300, 300))));   //在创景窗口中画一条直线
    line->setPen(QPen(Qt::DashDotDotLine));

    QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
    animation->setItem(line);
    //scene->addItem(animation);

    //怎样动需要QTimeLiness函数
    QTimeLine *timeline = new QTimeLine();      //持续三秒钟
    timeline->setLoopCount(NULL);                      //设置循环次数

    animation->setTimeLine(timeline);
    //animation->rotationAt(45);                      //以怎样的角度进行旋转
    animation->setTranslationAt(1, 200, 200);

    timeline->start();

    _timer = new QTimer();
    _timer->setInterval(1000);       //设置间隔时间
    connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimeOut()));
    _timer->start();
posted @ 2020-03-23 16:25  Werial  阅读(1259)  评论(0编辑  收藏  举报