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 so that 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 the mouse events in order to construct the paint program.

How to do it…

Let us start our fun project through the following steps:

  1. Again, we start by creating a new Qt Widgets Application project and removing the tool bar and status bar. We will keep the menu bar this time.
  2. After that, set up the menu bar like so:
  3. We will leave the menu ...

Get Qt5 C++ GUI Programming Cookbook 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.