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
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Displaying images on screen


Qt not only allows us to draw shapes and images on screen, but it also allows us to overlay multiple images on top of each other and combine the pixel information from all the layers using different types of algorithms to create very interesting results. In this example, we will learn how to overlay images on top of each other and apply different composition effects to them.

How to do it…

Let's create a simple demo that shows the effect of different image compositions by following these steps:

  1. First, set up a new Qt Widgets Application project and remove the menu bar, tool bar, and status bar.

  2. Next, add the QPainter class header to mainwindow.h:

    #include <QPainter>
  3. After that, declare the paintEvent() virtual function like so:

    virtual void paintEvent(QPaintEvent* event);
  4. In mainwindow.cpp, we will first load several image files using the QImage class:

    void MainWindow::paintEvent(QPaintEvent* event)
    {
      QImage image;
      image.load("checker.png");
    
      QImage image2;...