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:
- First, set up a new Qt Widgets Application project and remove the menu bar, tool bar, and status bar.
- Next, add the QPainter class header to
mainwindow.h
:#include <QPainter>
- After that, declare the
paintEvent()
virtual function like so:virtual void paintEvent(QPaintEvent* event);
- In
mainwindow.cpp
, we will first load several image files using theQImage
class:void MainWindow::paintEvent(QPaintEvent* event) { QImage image; image.load("checker.png"...