1. 程式人生 > 其它 >Qt之二維繪圖:QGraphicsScene與QPainterPath

Qt之二維繪圖:QGraphicsScene與QPainterPath

技術標籤:qtguiwindowsc++eclipse

新建一個QT GUI程式,選擇基類Widget,取消建立介面。修改main.cpp

#include "widget.h"
#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QPainterPath>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QPainterPath path;
    path.moveTo(30, 120);     //繪圖的起點
    path.cubicTo(80, 0, 50, 50, 80, 80);   //繪製貝塞爾曲線

    QGraphicsScene scene;

    scene.addPath(path, QPen(Qt::black), QBrush(Qt::green));
    scene.addText("I love Qt programming", QFont("Times", 15, QFont::Bold));

    QGraphicsView view(&scene);
    view.setAlignment(Qt::AlignLeft | Qt::AlignTop);  //

    view.show();

    return a.exec();
}

b0d40fe6fb8ac40019fe1bd2d974f387f9a.jpg