Qt之二維繪圖:QGraphicsScene與QPainterPath

新建一個QT GUI程序,選擇基類Widget,取消建立界面。修改main.cppcode

#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();
}

相關文章
相關標籤/搜索