Qt之二維繪圖:QGraphicsScene與QPainterPath
阿新 • 來源:網路 • 發佈:2021-02-20
新建一個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();
}

