⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 本文件是<精通QT4编程>的配套源代码
💻 CPP
字号:
#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();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -