描绘设备和后端

Creating a Paint Device

The QPaintDevice class is the base class of objects that can be painted, i.e. QPainter can draw on any QPaintDevice 子类。 QPaintDevice 's drawing capabilities are among others implemented by QWidget , QImage , QPixmap , QPicture , QPrinter ,和 QOpenGLPaintDevice .

Widget

The QWidget class 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.

图像

The QImage class provides a hardware-independent image representation which is designed and optimized for I/O, and for direct pixel access and manipulation. QImage supports several image formats including monochrome, 8-bit, 32-bit and alpha-blended images.

One advantage of using QImage as 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 QPixmap class is an off-screen image representation which is designed and optimized for showing images on screen. Unlike QImage , the pixel data in a pixmap is internal and is managed by the underlying window system, i.e. pixels can only be accessed through QPainter 函数或通过转换 QPixmap QImage .

To optimize drawing with QPixmap , Qt provides the QPixmapCache class 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 QBitmap convenience class, inheriting QPixmap . QBitmap guarantees monochrome (1-bit depth) pixmaps, and is mainly used for creating custom QCursor and QBrush 对象,构造 QRegion 对象。

OpenGL Paint Device

As mentioned previously, Qt is offering classes that makes it easy to use OpenGL in Qt applications. For example, the QOpenGLPaintDevice enables the OpenGL API for rendering with QPainter .

Picture

The QPicture 类是描绘设备,它记录并重演 QPainter commands. A picture serializes painter commands to an IO device in a platform-independent format. QPicture is also resolution independent, i.e. a QPicture can be displayed on different devices (for example svg, pdf, ps, printer and screen) looking the same.

Qt 提供 QPicture::load () 和 QPicture::save () 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 QPaintDevice class and reimplementing the virtual QPaintDevice::paintEngine () 函数以告诉 QPainter which 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 the QPaintEngine 类。

版权所有  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1