Setting up a new project

First, create a new Qt Widgets Application project. After that, open mainwindow.ui and drag and drop the Graphics View widget onto the main window, like this:

Then, create a layout for the graphics view by clicking on the Lay Out Vertically button at the top of the canvas. After that, open up mainwindow.h and add the following headers and variables:

#include <QGraphicsScene> 
#include <QGraphicsRectItem> 
#include <QGraphicsEllipseItem> 
#include <QGraphicsTextItem> 
#include <QBrush> 
#include <QPen> private:  Ui::MainWindow *ui;  QGraphicsScene* scene;

After that, open mainwindow.cpp. Once it is opened, add the following ...

Get Hands-On GUI Programming with C++ and Qt5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.