Drawing and Filling¶
QPainterprovides highly optimized functions to do most of the drawing GUI programs require. It can draw everything from simple graphical primitives (represented by the
QPolygonclasses) to complex shapes like vector paths. In Qt vector paths are represented by the
QPainterPathprovides a container for painting operations, enabling graphical shapes to be constructed and reused.
A painter path is an object composed of lines and curves. For example, a rectangle is composed by lines and an ellipse is composed by curves.
The main advantage of painter paths over normal drawing operations is that complex shapes only need to be created once; then they can be drawn many times using only calls to the
Lines and outlines are drawn using the
QPenclass. A pen is defined by its style (i.e. its line-type), width, brush, how the endpoints are drawn (cap-style) and how joins between two connected lines are drawn (join-style). The pen’s brush is a
QBrushobject used to fill strokes generated with the pen, i.e. the
QBrushclass defines the fill pattern.
QPaintercan also draw aligned text and pixmaps.
When drawing text, the font is specified using the
QFontclass. Qt will use the font with the specified attributes, or if no matching font exists, Qt will use the closest matching installed font. The attributes of the font that is actually used can be retrieved using the
QFontInfoclass. In addition, the
QFontMetricsclass provides the font measurements, and the
QFontDatabaseclass provides information about the fonts available in the underlying window system.
QPainterdraws in a “natural” coordinate system, but it is able to perform view and world transformations using the
QTransformclass. For more information, see Coordinate System , which also describes the rendering process, i.e. the relation between the logical representation and the rendered pixels, and the benefits of anti-aliased painting.
When drawing, the pixel rendering is controlled by the
Antialiasingrender hint. The
RenderHintenum is used to specify flags to
QPainterthat may or may not be respected by any given engine.
Antialiasingvalue indicates that the engine should antialias edges of primitives if possible, i.e. smoothing the edges by using different color intensities.
Shapes are filled using the
QBrushclass. A brush is defined by its color and its style (i.e. its fill pattern).
Any color in Qt is represented by the
QColorclass which supports the RGB, HSV and CMYK color models.
QColoralso support alpha-blended outlining and filling (specifying the transparency effect), and the class is platform and device independent (the colors are mapped to hardware using the
QColormapclass). For more information, see the
The available fill patterns are described by the
BrushStyleenum. These include basic patterns spanning from uniform color to very sparse pattern, various line combinations, gradient fills and textures. Qt provides the
QGradientclass to define custom gradient fills, while texture patterns are specified using the
Qt currently supports three types of gradient fills: Linear gradients interpolate colors between start and end points, radial gradients interpolate colors between a focal point and end points on a circle surrounding it, and conical gradients interpolate colors around a center point.
© 2020 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.