Creating a basic paint program
Since we have learned so much about the QPainter
class and how to use it to display graphics on screen, I guess it’s time for us to do something fun where we can put our knowledge into practice.
In this recipe, we will learn how to make a basic paint program that allows us to draw lines on a canvas with different brush sizes and colors. We will also learn how to use the QImage
class and mouse events in order to construct the paint program.
How to do it…
Let’s start our fun project with the following steps:
- Again, we start by creating a new Qt Widgets Application project and removing the toolbar and status bar. We will keep the menu bar this time.
- After that, set up the menu bar like so:
Figure 4.16 – Setting up the menu bar
- We will leave the menu bar as it is for the moment, so let’s proceed to the
mainwindow.h
file. First, include the following header files...