Book Image

Qt5 C++ GUI Programming Cookbook

By : Lee Zhi Eng
Book Image

Qt5 C++ GUI Programming Cookbook

By: Lee Zhi Eng

Overview of this book

With the advancement of computer technology, the software market is exploding with tons of software choices for the user, making their expectations higher in terms of functionality and the look and feel of the application. Therefore, improving the visual quality of your application is vital in order to overcome the market competition and stand out from the crowd. This book will teach you how to develop functional and appealing software using Qt5 through multiple projects that are interesting and fun. This book covers a variety of topics such as look-and-feel customization, GUI animation, graphics rendering, implementing Google Maps, and more. You will learn tons of useful information, and enjoy the process of working on the creative projects provided in this book
Table of Contents (16 chapters)
Qt5 C++ GUI Programming Cookbook
About the Author
About the Reviewer

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 bar as it is for the moment and let's proceed to mainwindow.h. First, include the following header files as it's required for the project:

    #include <QPainter>
    #include <QMouseEvent>
    #include <QFileDialog>
  4. Next, declare the variables...