2D and 3D Graphics
D and 3D Graphics
- Painting with QPainter
- Graphics with QCanvas
- Printing
- Graphics with OpenGL
In this chapter, we will explore Qt's graphics capabilities. The cornerstone of Qt's 2D drawing engine is QPainter, which can be used to draw on a widget on the screen, on an off-screen pixmap, or on a physical printer. Qt also includes a QCanvas class that provides a higher-level way of doing graphics, using an item-based approach that can efficiently handle thousands and thousands of items of various shapes. Many predefined items are provided, and it is easy to create custom canvas items.
An alternative to QPainter and QCanvas is to use the OpenGL library. OpenGL is a standard library for drawing 3D graphics, but it can also be used for drawing 2D graphics. It is very easy to integrate OpenGL code into Qt applications, as we will demonstrate.