当前位置: 代码迷 >> QT开发 >> 精通QT4编程里的一个简略动画的例题,求解
  详细解决方案

精通QT4编程里的一个简略动画的例题,求解

热度:112   发布时间:2016-04-25 04:42:53.0
精通QT4编程里的一个简单动画的例题,求解。
#include <QtGui>
#include <cmath>

using namespace std;

const qreal PI = 3.14159265;

int main(int argc, char* argv[])
{
  QApplication app(argc, argv);
  QGraphicsEllipseItem *sun = new QGraphicsEllipseItem(0, 0, 20, 20);
  sun->setBrush(Qt::red);
  sun->setPen(QPen(Qt::red));

  QTimeLine *timeline = new QTimeLine(10000);
  timeline->setCurveShape(QTimeLine::LinearCurve);
  //timeline->setFrameRange(0, 100);

  QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
  animation->setItem(sun);
  animation->setTimeLine(timeline);

  qreal x, y;
  qreal angle = PI;
  for (int i = 0; i <= 180; ++i)
  {
  x = 200.0 * cos(angle);
  y = 200.0 * sin(angle);
  qDebug() << x << y;
  animation->setPosAt(i/180.0, QPointF(x, y));
  angle += PI/180.0;
  }

  QGraphicsScene *scene = new QGraphicsScene();
  scene->addItem(sun);

  QGraphicsView *view = new QGraphicsView(scene);
  view->resize(640,480);
  view->show();

  timeline->start();
  return app.exec();
}

问下,为什么这样画的不是个圈而是个半圆呢,而且发现原点(0 , 0)好像在动(调试的时候我在圆点画了个蓝色的圆点)。如果我想画个圆该怎么画呢?

------解决方案--------------------
我想画直线都不会,唉
  相关解决方案