Paint Devices and Backends¶
Creating a Paint Device¶
The
QPaintDeviceclass is the base class of objects that can be painted, i.e.QPaintercan draw on anyQPaintDevicesubclass.QPaintDevice‘s drawing capabilities are among others implemented byQWidget,QImage,QPixmap,QPicture,QPrinter, andQOpenGLPaintDevice.
Widget
The
QWidgetclass is the base class of user interface elements in the Qt Widgets module. It receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen.Image
The
QImageclass provides a hardware-independent image representation which is designed and optimized for I/O, and for direct pixel access and manipulation.QImagesupports several image formats including monochrome, 8-bit, 32-bit and alpha-blended images.One advantage of using
QImageas a paint device is that it is possible to guarantee the pixel exactness of any drawing operation in a platform-independent way. Another benefit is that the painting can be performed in another thread than the current GUI thread.Pixmap
The
QPixmapclass is an off-screen image representation which is designed and optimized for showing images on screen. UnlikeQImage, the pixel data in a pixmap is internal and is managed by the underlying window system, i.e. pixels can only be accessed throughQPainterfunctions or by converting theQPixmapto aQImage.To optimize drawing with
QPixmap, Qt provides theQPixmapCacheclass which can be used to store temporary pixmaps that are expensive to generate without using more storage space than the cache limit.Qt also provides the
QBitmapconvenience class, inheritingQPixmap.QBitmapguarantees monochrome (1-bit depth) pixmaps, and is mainly used for creating customQCursorandQBrushobjects, constructingQRegionobjects.OpenGL Paint Device
As mentioned previously, Qt is offering classes that makes it easy to use OpenGL in Qt applications. For example, the
QOpenGLPaintDeviceenables the OpenGL API for rendering withQPainter.Picture
The
QPictureclass is a paint device that records and replaysQPaintercommands. A picture serializes painter commands to an IO device in a platform-independent format.QPictureis also resolution independent, i.e. aQPicturecan be displayed on different devices (for example svg, pdf, ps, printer and screen) looking the same.Qt provides the
load()andsave()functions as well as streaming operators for loading and saving pictures.Custom Backends
Support for a new backend can be implemented by deriving from the
QPaintDeviceclass and reimplementing the virtualpaintEngine()function to tellQPainterwhich paint engine should be used to draw on this particular device. To actually be able to draw on the device, this paint engine must be a custom paint engine created by deriving from theQPaintEngineclass.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.