新建一个QT GUI程序,选择基类Widget,取消创建界面。修改main.cpp
#include "widget.h"#include#include #include #include 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();}