First, create another Qt project by going to File | New File or Project. Then select Qt Widget Application under the Application category. After the project has been created, open up mainwindow.h and add in the QPainter header:
#include <QMainWindow> #include <QPainter>
After that, we also declare a virtual function called paintEvent(), which is a standard event handler in Qt that gets called whenever there is something that needs to be painted, be it a GUI update, a window resize, or when the update() function is being called manually:
public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); virtual void paintEvent(QPaintEvent *event);
Then, open up mainwindow.cpp and add the paintEvent() function: ...