Graphics in Qt 5 is primarily done either through the imperative QPainter API, or through Qt’s declarative UI language, Qt Quick, and its scene graph back-end. Qt 5's graphics capabilities also includes support for printing, as well as the loading and saving of various image formats.
QPainter provides API for drawing vector graphics, text and images onto different surfaces, or QPaintDevice instances, such as QImage , QOpenGLPaintDevice , QWidget ，和 QPrinter . The actual drawing happens in the QPaintDevice 's QPaintEngine . The software rasterizer and the OpenGL (ES) 2.0 back-ends are the two most important QPaintEngine implementations. The raster paint engine is Qt’s software rasterizer, and is used when drawing on a QImage or QWidget . Its strength over the OpenGL paint engine is its high quality when antialiasing is enabled, and a complete feature set.
The most important rendering targets for QPainter are:
OpenGL is the most widely adopted graphics API for hardware accelerated and 3D graphics, implemented on all desktop platforms and almost every mobile and embedded platform. The Qt library contains a number of classes that help users integrate OpenGL into their applications.
Prior to Qt 5.0, OpenGL support in Qt was handled by the
module. This module is still present, but new code should aim to use the new classes in the
module. The classes are easily distinguisible based on their names: Classes with the
prefix should not be used. Instead, prefer the ones starting with
Qt Quick 2 introduces an OpenGL (ES) 2.0 scene graph for rendering. It generally improves the performance of Qt Quick 2 significantly compared to the QGraphicsView / QPainter -based approach used in earlier versions.
The scene graph is a graphical representation of the Item scene. It can be thought of as a graphical deep copy, an independent structure that contains enough information to render all the items. Once it has been set up, it can be manipulated and rendered independently of the state of the items. On many platforms, the scene graph will even be rendered on a dedicated render thread while the GUI thread is preparing the next frame's state.
Qt Quick can be mixed with raw OpenGL rendering by connecting to the signals QQuickWindow::beforeRendering () 或 QQuickWindow::afterRendering () which are emitted before and after the Qt Quick scene graph is rendered, respectively. There signals are emitted from the render thread (when applicable), and the connections need to be direct.
Qt Quick can also be rendered using Qt Quick 2D Renderer . This raster paint engine enables rendering Qt Quick applications on platforms that do not have OpenGL.
Qt supports printing both directly to actual printers, locally or on the network, as well as producing PDF output. How to do printing with Qt is described in detail on the Qt Print Support 页面。
Qt supports convenient reading, writing, and manipulating of images through the QImage class. In addition, for more fine grained control of how images are loaded or saved, you can use the QImageReader and QImageWriter classes respectively. To add support for additional image formats, outside of the ones provided by Qt, you can create image format plugins by using QImageIOHandler and QImageIOPlugin .
见 读写图像文件 页面，了解更多信息。
另请参阅 描绘系统 .