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
menuBar
,mainToolBar
, andstatusBar
, as we did in the first recipe. - Next, add the
QPainter
class header to themainwindow.h
file:#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...