CopperSpice API
1.9.2
|
Performs low level painting operations on widgets and other paint devices. More...
Classes | |
class | PixmapFragment |
A class used in conjunction with QPainter::drawPixmapFragments() to specify how a pixmap is drawn More... | |
Public Typedefs | |
using | PixmapFragmentHints = QFlags< PixmapFragmentHint > |
using | RenderHints = QFlags< RenderHint > |
Public Types | |
enum | CompositionMode |
enum | PixmapFragmentHint |
enum | RenderHint |
Public Methods | |
QPainter () | |
QPainter (QPaintDevice *device) | |
~QPainter () | |
const QBrush & | background () const |
Qt::BGMode | backgroundMode () const |
bool | begin (QPaintDevice *device) |
void | beginNativePainting () |
QRect | boundingRect (const QRect &rect, int flags, const QString &text) |
QRectF | boundingRect (const QRectF &rect, const QString &text, const QTextOption &option=QTextOption ()) |
QRectF | boundingRect (const QRectF &rect, int flags, const QString &text) |
QRect | boundingRect (int x, int y, int width, int height, int flags, const QString &text) |
const QBrush & | brush () const |
QPoint | brushOrigin () const |
QRectF | clipBoundingRect () const |
QPainterPath | clipPath () const |
QRegion | clipRegion () const |
QMatrix | combinedMatrix () const |
QTransform | combinedTransform () const |
CompositionMode | compositionMode () const |
QPaintDevice * | device () const |
const QMatrix & | deviceMatrix () const |
const QTransform & | deviceTransform () const |
void | drawArc (const QRect &rect, int startAngle, int arcLength) |
void | drawArc (const QRectF &rect, int startAngle, int arcLength) |
void | drawArc (int x, int y, int width, int height, int startAngle, int arcLength) |
void | drawChord (const QRect &rect, int startAngle, int arcLength) |
void | drawChord (const QRectF &rect, int startAngle, int arcLength) |
void | drawChord (int x, int y, int width, int height, int startAngle, int arcLength) |
void | drawConvexPolygon (const QPoint *points, int pointCount) |
void | drawConvexPolygon (const QPointF *points, int pointCount) |
void | drawConvexPolygon (const QPolygon &polygon) |
void | drawConvexPolygon (const QPolygonF &polygon) |
void | drawEllipse (const QPoint ¢er, int rx, int ry) |
void | drawEllipse (const QPointF ¢er, qreal rx, qreal ry) |
void | drawEllipse (const QRect &rect) |
void | drawEllipse (const QRectF &rect) |
void | drawEllipse (int x, int y, int width, int height) |
void | drawGlyphRun (const QPointF &point, const QGlyphRun &glyphs) |
void | drawImage (const QPoint &point, const QImage &image) |
void | drawImage (const QPoint &point, const QImage &image, const QRect &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor) |
void | drawImage (const QPointF &point, const QImage &image) |
void | drawImage (const QPointF &point, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor) |
void | drawImage (const QRect &rect, const QImage &image) |
void | drawImage (const QRect &targetRect, const QImage &image, const QRect &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor) |
void | drawImage (const QRectF &rect, const QImage &image) |
void | drawImage (const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor) |
void | drawImage (int x, int y, const QImage &image, int sx=0, int sy=0, int sw=-1, int sh=-1, Qt::ImageConversionFlags flags=Qt::AutoColor) |
void | drawLine (const QLine &line) |
void | drawLine (const QLineF &line) |
void | drawLine (const QPoint &point1, const QPoint &point2) |
void | drawLine (const QPointF &point1, const QPointF &point2) |
void | drawLine (int x1, int y1, int x2, int y2) |
void | drawLines (const QLine *lines, int lineCount) |
void | drawLines (const QLineF *lines, int lineCount) |
void | drawLines (const QPoint *points, int lineCount) |
void | drawLines (const QPointF *points, int lineCount) |
void | drawLines (const QVector< QLine > &lines) |
void | drawLines (const QVector< QLineF > &lines) |
void | drawLines (const QVector< QPoint > &points) |
void | drawLines (const QVector< QPointF > &points) |
void | drawPath (const QPainterPath &path) |
void | drawPicture (const QPoint &point, const QPicture &picture) |
void | drawPicture (const QPointF &point, const QPicture &picture) |
void | drawPicture (int x, int y, const QPicture &picture) |
void | drawPie (const QRect &rect, int startAngle, int arcLength) |
void | drawPie (const QRectF &rect, int startAngle, int arcLength) |
void | drawPie (int x, int y, int width, int height, int startAngle, int arcLength) |
void | drawPixmap (const QPoint &point, const QPixmap &pixmap) |
void | drawPixmap (const QPoint &point, const QPixmap &pixmap, const QRect &sourceRect) |
void | drawPixmap (const QPointF &point, const QPixmap &pixmap) |
void | drawPixmap (const QPointF &point, const QPixmap &pixmap, const QRectF &sourceRect) |
void | drawPixmap (const QRect &rect, const QPixmap &pixmap) |
void | drawPixmap (const QRect &targetRect, const QPixmap &pixmap, const QRect &sourceRect) |
void | drawPixmap (const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect) |
void | drawPixmap (int x, int y, const QPixmap &pixmap) |
void | drawPixmap (int x, int y, const QPixmap &pixmap, int sx, int sy, int sw, int sh) |
void | drawPixmap (int x, int y, int width, int height, const QPixmap &pixmap) |
void | drawPixmap (int x, int y, int width, int height, const QPixmap &pixmap, int sx, int sy, int sw, int sh) |
void | drawPixmapFragments (const PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, PixmapFragmentHints hints=PixmapFragmentHints ()) |
void | drawPoint (const QPoint &point) |
void | drawPoint (const QPointF &point) |
void | drawPoint (int x, int y) |
void | drawPoints (const QPoint *points, int pointCount) |
void | drawPoints (const QPointF *points, int pointCount) |
void | drawPoints (const QPolygon &polygon) |
void | drawPoints (const QPolygonF &polygon) |
void | drawPolygon (const QPoint *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill) |
void | drawPolygon (const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill) |
void | drawPolygon (const QPolygon &polygon, Qt::FillRule fillRule=Qt::OddEvenFill) |
void | drawPolygon (const QPolygonF &polygon, Qt::FillRule fillRule=Qt::OddEvenFill) |
void | drawPolyline (const QPoint *points, int pointCount) |
void | drawPolyline (const QPointF *points, int pointCount) |
void | drawPolyline (const QPolygon &polygon) |
void | drawPolyline (const QPolygonF &polygon) |
void | drawRect (const QRect &rect) |
void | drawRect (const QRectF &rect) |
void | drawRect (int x, int y, int width, int height) |
void | drawRects (const QRect *rects, int rectCount) |
void | drawRects (const QRectF *rects, int rectCount) |
void | drawRects (const QVector< QRect > &rectangles) |
void | drawRects (const QVector< QRectF > &rectangles) |
void | drawRoundedRect (const QRect &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize) |
void | drawRoundedRect (const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize) |
void | drawRoundedRect (int x, int y, int width, int height, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize) |
void | drawRoundRect (const QRect &rect, int xRound=25, int yRound=25) |
void | drawRoundRect (const QRectF &rect, int xRound=25, int yRound=25) |
void | drawRoundRect (int x, int y, int width, int height, int xRound=25, int yRound=25) |
void | drawStaticText (const QPoint &topLeftPosition, const QStaticText &staticText) |
void | drawStaticText (const QPointF &topLeftPosition, const QStaticText &staticText) |
void | drawStaticText (int left, int top, const QStaticText &staticText) |
void | drawText (const QPoint &point, const QString &text) |
void | drawText (const QPointF &point, const QString &text) |
void | drawText (const QRect &rect, int flags, const QString &text, QRect *boundingRect=nullptr) |
void | drawText (const QRectF &rect, const QString &text, const QTextOption &option=QTextOption ()) |
void | drawText (const QRectF &rect, int flags, const QString &text, QRectF *boundingRect=nullptr) |
void | drawText (int x, int y, const QString &text) |
void | drawText (int x, int y, int width, int height, int flags, const QString &text, QRect *boundingRect=nullptr) |
void | drawTiledPixmap (const QRect &rect, const QPixmap &pixmap, const QPoint &point=QPoint ()) |
void | drawTiledPixmap (const QRectF &rect, const QPixmap &pixmap, const QPointF &point=QPointF ()) |
void | drawTiledPixmap (int x, int y, int width, int height, const QPixmap &pixmap, int sx=0, int sy=0) |
bool | end () |
void | endNativePainting () |
void | eraseRect (const QRect &rect) |
void | eraseRect (const QRectF &rect) |
void | eraseRect (int x, int y, int width, int height) |
void | fillPath (const QPainterPath &path, const QBrush &brush) |
void | fillRect (const QRect &rect, const QBrush &brush) |
void | fillRect (const QRect &rect, const QColor &color) |
void | fillRect (const QRect &rect, Qt::BrushStyle style) |
void | fillRect (const QRect &rect, Qt::GlobalColor color) |
void | fillRect (const QRectF &rect, const QBrush &brush) |
void | fillRect (const QRectF &rect, const QColor &color) |
void | fillRect (const QRectF &rect, Qt::BrushStyle style) |
void | fillRect (const QRectF &rect, Qt::GlobalColor color) |
void | fillRect (int x, int y, int width, int height, const QBrush &brush) |
void | fillRect (int x, int y, int width, int height, const QColor &color) |
void | fillRect (int x, int y, int width, int height, Qt::BrushStyle style) |
void | fillRect (int x, int y, int width, int height, Qt::GlobalColor color) |
const QFont & | font () const |
QFontInfo | fontInfo () const |
QFontMetrics | fontMetrics () const |
bool | hasClipping () const |
void | initFrom (const QPaintDevice *device) |
bool | isActive () const |
Qt::LayoutDirection | layoutDirection () const |
const QMatrix & | matrix () const |
bool | matrixEnabled () const |
qreal | opacity () const |
QPaintEngine * | paintEngine () const |
const QPen & | pen () const |
RenderHints | renderHints () const |
void | resetMatrix () |
void | resetTransform () |
void | restore () |
void | rotate (qreal angle) |
void | save () |
void | scale (qreal sx, qreal sy) |
void | setBackground (const QBrush &brush) |
void | setBackgroundMode (Qt::BGMode mode) |
void | setBrush (const QBrush &brush) |
void | setBrush (Qt::BrushStyle style) |
void | setBrushOrigin (const QPoint &point) |
void | setBrushOrigin (const QPointF &point) |
void | setBrushOrigin (int x, int y) |
void | setClipPath (const QPainterPath &path, Qt::ClipOperation operation=Qt::ReplaceClip) |
void | setClipping (bool enable) |
void | setClipRect (const QRect &rect, Qt::ClipOperation operation=Qt::ReplaceClip) |
void | setClipRect (const QRectF &rect, Qt::ClipOperation operation=Qt::ReplaceClip) |
void | setClipRect (int x, int y, int width, int height, Qt::ClipOperation operation=Qt::ReplaceClip) |
void | setClipRegion (const QRegion ®ion, Qt::ClipOperation operation=Qt::ReplaceClip) |
void | setCompositionMode (CompositionMode mode) |
void | setFont (const QFont &font) |
void | setLayoutDirection (Qt::LayoutDirection direction) |
void | setMatrix (const QMatrix &matrix, bool combine=false) |
void | setMatrixEnabled (bool enable) |
void | setOpacity (qreal opacity) |
void | setPen (const QColor &color) |
void | setPen (const QPen &pen) |
void | setPen (Qt::PenStyle style) |
void | setRenderHint (RenderHint hint, bool on=true) |
void | setRenderHints (RenderHints hints, bool on=true) |
void | setTransform (const QTransform &transform, bool combine=false) |
void | setViewport (const QRect &viewport) |
void | setViewport (int x, int y, int width, int height) |
void | setViewTransformEnabled (bool enable) |
void | setWindow (const QRect &window) |
void | setWindow (int x, int y, int width, int height) |
void | setWorldMatrix (const QMatrix &matrix, bool combine=false) |
void | setWorldMatrixEnabled (bool enable) |
void | setWorldTransform (const QTransform &matrix, bool combine=false) |
void | shear (qreal sh, qreal sv) |
void | strokePath (const QPainterPath &path, const QPen &pen) |
bool | testRenderHint (RenderHint hint) const |
const QTransform & | transform () const |
void | translate (const QPoint &offset) |
void | translate (const QPointF &offset) |
void | translate (qreal dx, qreal dy) |
QRect | viewport () const |
bool | viewTransformEnabled () const |
QRect | window () const |
const QMatrix & | worldMatrix () const |
bool | worldMatrixEnabled () const |
const QTransform & | worldTransform () const |
Static Public Methods | |
static QPaintDevice * | redirected (const QPaintDevice *device, QPoint *point=nullptr) |
static void | restoreRedirected (const QPaintDevice *device) |
static void | setRedirected (const QPaintDevice *device, QPaintDevice *replacement, const QPoint &point=QPoint ()) |
Friends | |
class | QPaintEngine |
class | QRasterPaintEngine |
class | QWidget |
The QPainter class performs low level painting operations on widgets and other paint devices.
QPainter provides highly optimized methods to do many of the drawing operations required for a GUI program. The class can draw everything from simple lines to complex shapes like pies and chords. It can also draw aligned text and pixmaps. Normally, it draws in a "native" coordinate system, but it can also draw using view and world transformations. QPainter can draw on any object which inherits the QPaintDevice class.
The following example shows how to create a custom widget using a QPainter object. This paintEvent() method will be called by the event system whenever the widget needs to be repainted.
The core functionality of QPainter is for drawing however the class also provides several methods that allow customizing QPainter settings. Some of the setting control rendering quality, enable clipping, or how different shapes can be merged together.
Using this class with the QPaintDevice and QPaintEngine classes forms the basis for the CopperSpice paint system. QPainter is the class used to perform drawing operations. QPaintDevice represents a device which can be painted on using a QPainter. QPaintEngine provides the interface the painter uses to draw on different types of devices.
The isActive() method indicates whether the painter is active. A painter is activated by the begin() method and the constructor that takes a QPaintDevice argument. The end() method and the destructor deactivates the painter. If the painter object is active then the device() method returns the paint device on which the painter paints and paintEngine() returns the paint engine that the painter is currently operating on.
For more information refer to the Painting System.
There are several settings which can be used to customize and make QPainter draw according to your preferences. Some of these settings mirror other settings in some paint devices, for example QWidget::font(). The QPainter::begin() method or the QPainter constructor copy these attributes from the paint device.
You can save the QPainter's state by calling the save() method which saves all the available settings on an internal stack. The restore() method pops them back.
QPainter provides methods to draw most primitives: drawPoint(), drawPoints(), drawLine(), drawRect(), drawRoundedRect(), drawEllipse(), drawArc(), drawPie(), drawChord(), drawPolyline(), drawPolygon(), drawConvexPolygon(), and drawCubicBezier(). The methods drawRects() and drawLines() draw the given number of rectangles or lines in the given array of QRect or QLine using the current pen and brush.
The QPainter class also provides the fillRect() method which fills the given QRect with the given QBrush, and the eraseRect() method that erases the area inside the given rectangle.
All of these methods have both integer and floating point versions. If you need to draw a complex shape, especially if you need to do so repeatedly, consider creating a QPainterPath and drawing it using drawPath(). The QPainterPath class provides a container for painting operations, enabling graphical shapes to be constructed and reused.
QPainter also provides the fillPath() method which fills the given QPainterPath with the given QBrush, and the strokePath() method that draws the outline of the given path. There are methods to draw pixmaps/images, namely drawPixmap(), drawImage() and drawTiledPixmap(). Both drawPixmap() and drawImage() produce the same result, except that drawPixmap() is faster on-screen while drawImage() may be faster on a QPrinter or other devices.
Text drawing is done using drawText(). When you need fine grained positioning, boundingRect() tells you where a given drawText() command will draw.
There are methods to draw pixmaps/images, namely drawPixmap(), drawImage() and drawTiledPixmap(). Both drawPixmap() and drawImage() produce the same result, except drawPixmap() is faster on screen while drawImage() may be faster on a QPrinter or other devices.
The drawPicture() method draws the contents of an entire QPicture. The drawPicture() method is the only one which disregards all the painter's settings as QPicture has its own settings.
High resolution versions of pixmaps have a device pixel ratio value larger than 1.
If the pixel ratio matches the value of the underlying QPaintDevice, the pixmap is drawn directly with no additional transformation applied. This occurs when drawing a QPixmap of 64x64 pixels size with a device pixel ratio of 2 onto a high DPI screen which also has a device pixel ratio of 2. The pixmap is then effectively 32x32 pixels in user coordinates. Code paths in CopperSpice that calculate layout geometry based on the pixmap size will use this size. The net effect of this is that the pixmap is displayed as high DPI pixmap rather than a large pixmap.
To obtain a consistent rendering result using QPainter specify a QImage for the paint device. Using QImage will ensure that the result has an identical pixel representation on any platform.
The QPainter class also provides a means of controlling the rendering quality through its RenderHint enum and the support for floating point precision. All the methods for drawing primitives have a floating point version. These are often used in combination with the QPainter::Antialiasing render hint.
The RenderHint enum specifies flags to QPainter that may or may not be respected by any given engine. QPainter::Antialiasing indicates that the engine should antialias edges of primitives if possible, QPainter::TextAntialiasing indicates that the engine should antialias text if possible, and the QPainter::SmoothPixmapTransform indicates that the engine should use a smooth pixmap transformation algorithm.
The renderHints() method returns a flag which specifies the current rendering hints for this painter. Use the setRenderHint() method to change the RenderHints.
Normally, the QPainter operates on a device native coordinate system (usually pixels). However, QPainter does support coordinate transformations.
original | rotate() | scale() | translate() |
---|---|---|---|
The most commonly used transformations are scaling, rotation, translation and shearing. Use the scale() method to scale the coordinate system by a given offset, the rotate() method to rotate it clockwise and translate() to translate it. You can also twist the coordinate system around the origin using the shear() method.
All the transformation operations operate on the transformation worldTransform(). A matrix transforms a point in the plane to another point.
The setWorldTransform() function can replace or add to the currently set worldTransform(). The resetTransform() function resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldTransform(), setViewport() and setWindow() functions. The deviceTransform() returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device. The latter function is only needed when using platform painting commands on the platform dependent handle, and the platform does not do transformations natively.
When drawing with QPainter, we specify points using logical coordinates which then are converted into the physical coordinates of the paint device. The mapping of the logical coordinates to the physical coordinates are handled by QPainter's combinedTransform(), a combination of viewport() and window() and worldTransform(). The viewport() represents the physical coordinates specifying an arbitrary rectangle, the window() describes the same rectangle in logical coordinates, and the worldTransform() is identical with the transformation matrix.
QPainter can clip any drawing operation to a rectangle, a region, or a vector path. The current clip is available using the functions clipRegion() and clipPath(). Whether paths or regions are preferred (faster) depends on the underlying paintEngine(). For example, the QImage paint engine prefers paths while the X11 paint engine prefers regions. Setting a clip is done in the painters logical coordinates.
After the QPainter does clipping, the paint device may also clip. For example, most widgets clip away the pixels used by child widgets, and most printers clip away an area near the edges of the paper. This additional clipping is not reflected by the return value of clipRegion() or hasClipping().
QPainter provides the CompositionMode enum which defines the Porter-Duff rules for digital image compositing. It describes a model for combining the pixels in one image, the source, with the pixels in another image, the destination.
The two most common forms of composition are Source and SourceOver. Source is used to draw opaque objects onto a paint device. In this mode each pixel in the source replaces the corresponding pixel in the destination. In SourceOver composition mode the source object is transparent and is drawn on top of the destination.
Composition transformations operate on each pixel. For this reason, there is a difference between using the graphic primitive itself and its bounding rectangle. The bounding rectangle contains pixels with alpha == 0 (i.e the pixels surrounding the primitive). These pixels will overwrite the other image's pixels, effectively clearing those, while the primitive only overwrites its own area.
When using coordinates with the CopperSpice raster-based paint engine anything outside the range of +/- 215 is not guaranteed to be shown and the drawing may be clipped.
The outlines generated by the stroker are only an approximation for curved shapes. It is typically not possible to represent the bezier curve segment using another bezier curve segment, so CopperSpice approximates the curve outlines. For performance reasons there is a limit to how many curves are used. When using large pen widths or scales the outline error increases. To generate outlines with smaller errors use the QPainterPathStroker class and call the setCurveThreshold method to specify the error tolerance. Another option is to convert the paths to polygons first and then draw the polygons instead.
QPainter allows developers to do a variety of graphical operations, such as gradients, composition modes and vector graphics. These operations are supported on a variety of different hardware and software stacks.The underlying combination of hardware and software has some implications for performance. Optimizing every combination of operations is not practical.
The backends we focus on as high-performance engines are the following two.
The high performance operations are listed below.
drawPixmap()
in combination with simple transformations and opacity with non-smooth transformation mode (QPainter::SmoothPixmapTransform
not enabled as a render hint). QPainter::CompositionMode_Source
and QPainter::CompositionMode_SourceOver Typedef for QFlags<PixmapFragmentHint> which contains an OR combination of PixmapFragmentHint values.
Refer to QPainter::PixmapFragmentHint for the enum documentation.
Typedef for QFlags<RenderHint> which contains an OR combination of RenderHint values.
Refer to QPainter::RenderHint for the enum documentation.
Defines the modes supported for digital image compositing. Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.
Please note that the bitwise raster operation modes, denoted with a RasterOp prefix, are only natively supported in the X11 and raster paint engines. This means that the only way to utilize these modes on the Mac is via a QImage. The RasterOp denoted blend modes are not supported for pens and brushes with alpha components. Also, turning on the QPainter::Antialiasing render hint will effectively disable the RasterOp modes.
The most common type is SourceOver (often referred to as just alpha blending) where the source pixel is blended on top of the destination pixel in such a way that the alpha component of the source defines the translucency of the pixel.
When the paint device is a QImage, the image format must be set to Format_ARGB32Premultiplied or Format_ARGB32 for the composition modes to have any effect. For performance the premultiplied version is the preferred format.
When a composition mode is set it applies to all painting operator, pens, brushes, gradients and pixmap/image drawing.
Constant | Value | Description |
---|---|---|
QPainter::CompositionMode_SourceOver | 0 | This is the default mode. The alpha of the source is used to blend the pixel on top of the destination. |
QPainter::CompositionMode_DestinationOver | 1 | The alpha of the destination is used to blend it on top of the source pixels. This mode is the inverse of CompositionMode_SourceOver. |
QPainter::CompositionMode_Clear | 2 | The pixels in the destination are cleared (set to fully transparent) independent of the source. |
QPainter::CompositionMode_Source | 3 | The output is the source pixel. (This means a basic copy operation and is identical to SourceOver when the source pixel is opaque). |
QPainter::CompositionMode_Destination | 4 | The output is the destination pixel. This means that the blending has no effect. This mode is the inverse of CompositionMode_Source. |
QPainter::CompositionMode_SourceIn | 5 | The output is the source, where the alpha is reduced by that of the destination. |
QPainter::CompositionMode_DestinationIn | 6 | The output is the destination, where the alpha is reduced by that of the source. This mode is the inverse of CompositionMode_SourceIn. |
QPainter::CompositionMode_SourceOut | 7 | The output is the source, where the alpha is reduced by the inverse of destination. |
QPainter::CompositionMode_DestinationOut | 8 | The output is the destination, where the alpha is reduced by the inverse of the source. This mode is the inverse of CompositionMode_SourceOut. |
QPainter::CompositionMode_SourceAtop | 9 | The source pixel is blended on top of the destination, with the alpha of the source pixel reduced by the alpha of the destination pixel. |
QPainter::CompositionMode_DestinationAtop | 10 | The destination pixel is blended on top of the source, with the alpha of the destination pixel is reduced by the alpha of the destination pixel. This mode is the inverse of CompositionMode_SourceAtop. |
QPainter::CompositionMode_Xor | 11 | The source, whose alpha is reduced with the inverse of the destination alpha, is merged with the destination, whose alpha is reduced by the inverse of the source alpha. CompositionMode_Xor is not the same as the bitwise Xor. |
QPainter::CompositionMode_Plus | 12 | Both the alpha and color of the source and destination pixels are added together. |
QPainter::CompositionMode_Multiply | 13 | The output is the source color multiplied by the destination. Multiplying a color with white leaves the color unchanged, while multiplying a color with black produces black. |
QPainter::CompositionMode_Screen | 14 | The source and destination colors are inverted and then multiplied. Screening a color with white produces white, whereas screening a color with black leaves the color unchanged. |
QPainter::CompositionMode_Overlay | 15 | Multiplies or screens the colors depending on the destination color. The destination color is mixed with the source color to reflect the lightness or darkness of the destination. |
QPainter::CompositionMode_Darken | 16 | The darker of the source and destination colors is selected. |
QPainter::CompositionMode_Lighten | 17 | The lighter of the source and destination colors is selected. |
QPainter::CompositionMode_ColorDodge | 18 | The destination color is brightened to reflect the source color. A black source color leaves the destination color unchanged. |
QPainter::CompositionMode_ColorBurn | 19 | The destination color is darkened to reflect the source color. A white source color leaves the destination color unchanged. |
QPainter::CompositionMode_HardLight | 20 | Multiplies or screens the colors depending on the source color. A light source color will lighten the destination color, whereas a dark source color will darken the destination color. |
QPainter::CompositionMode_SoftLight | 21 | Darkens or lightens the colors depending on the source color. Similar to CompositionMode_HardLight. |
QPainter::CompositionMode_Difference | 22 | Subtracts the darker of the colors from the lighter. Painting with white inverts the destination color, whereas painting with black leaves the destination color unchanged. |
QPainter::CompositionMode_Exclusion | 23 | Similar to CompositionMode_Difference, but with a lower contrast. Painting with white inverts the destination color, whereas painting with black leaves the destination color unchanged. |
QPainter::RasterOp_SourceOrDestination | 24 | Does a bitwise OR operation on the source and destination pixels (src OR dst). |
QPainter::RasterOp_SourceAndDestination | 25 | Does a bitwise AND operation on the source and destination pixels (src AND dst). |
QPainter::RasterOp_SourceXorDestination | 26 | Does a bitwise XOR operation on the source and destination pixels (src XOR dst). |
QPainter::RasterOp_NotSourceAndNotDestination | 27 | Does a bitwise NOR operation on the source and destination pixels ((NOT src) AND (NOT dst)). |
QPainter::RasterOp_NotSourceOrNotDestination | 28 | Does a bitwise NAND operation on the source and destination pixels ((NOT src) OR (NOT dst)). |
QPainter::RasterOp_NotSourceXorDestination | 29 | Does a bitwise operation where the source pixels are inverted and then XOR'ed with the destination ((NOT src) XOR dst). |
QPainter::RasterOp_NotSourceXorDestination | 29 | Does a bitwise operation where the source pixels are inverted and then XOR'ed with the destination ((NOT src) XOR dst). |
QPainter::RasterOp_NotSource | 30 | Does a bitwise operation where the source pixels are inverted (NOT src). |
QPainter::RasterOp_NotSourceAndDestination | 31 | Does a bitwise operation where the source is inverted and then AND'ed with the destination ((NOT src) AND dst). |
QPainter::RasterOp_SourceAndNotDestination | 32 | Does a bitwise operation where the source is AND'ed with the inverted destination pixels (src AND (NOT dst)). |
QPainter::RasterOp_NotSourceOrDestination | 33 | Does a bitwise operation where the source is inverted and then OR'ed with the destination ((NOT src) OR dst). |
QPainter::RasterOp_SourceOrNotDestination | 34 | Does a bitwise operation where the source is OR'ed with the inverted destination pixels (src OR (NOT dst)). |
QPainter::RasterOp_ClearDestination | 35 | Pixels in the destination are cleared (set to 0) independent of the source. |
QPainter::RasterOp_SetDestination | 36 | Pixels in the destination are set (set to 1) independent of the source. |
QPainter::RasterOp_NotDestination | 37 | Does a bitwise operation where the destination pixels are inverted (NOT dst). |
Constant | Value | Description |
---|---|---|
QPainter::OpaqueHint | 0x01 | Indicates that the pixmap fragments to be drawn are opaque. Opaque fragments are potentially faster to draw. |
enum QPainter::RenderHint |
Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine.
Constant | Value | Description |
---|---|---|
QPainter::Antialiasing | 0x01 | Indicates that the engine should antialias edges of primitives if possible. |
QPainter::TextAntialiasing | 0x02 | Indicates that the engine should antialias text if possible. To forcibly disable antialiasing for text, do not use this hint. Instead, set QFont::NoAntialias on your font's style strategy. |
QPainter::SmoothPixmapTransform | 0x04 | Indicates that the engine should use a smooth pixmap transformation algorithm (such as bilinear) rather than nearest neighbor. |
QPainter::HighQualityAntialiasing | 0x08 | An OpenGL-specific rendering hint indicating that the engine should use fragment programs and offscreen rendering for antialiasing. |
QPainter::NonCosmeticDefaultPen | 0x10 | The engine should interpret pens with a width of 0 (which otherwise enables QPen::isCosmetic()) as being a non-cosmetic pen with a width of 1. |
|
explicit |
Constructs a painter which begins painting the device immediately. Calls begin() and the destructor automatically calls end(). This constructor is convenient for short lived painters like QWidget::paintEvent() and should be used only once.
The following is an example using the begin() and end() methods. Since the constructor does not provide feedback if the initialization fails, it is usually better to use begin() and end() to paint on external devices.
This code produces the same result using this constructor.
QPainter::~QPainter | ( | ) |
Destroys the QPainter.
const QBrush & QPainter::background | ( | ) | const |
Returns the current background brush.
Qt::BGMode QPainter::backgroundMode | ( | ) | const |
Returns the current background mode.
bool QPainter::begin | ( | QPaintDevice * | device | ) |
Begins painting the paint device and returns true if successful, otherwise returns false. All painter settings such as setPen() and setBrush() are reset to default values when begin() is called. A paint device can only be painted by one painter at a time.
The following code shows some of the errors which can occur.
void QPainter::beginNativePainting | ( | ) |
Flushes the painting pipeline and prepares for the user issuing commands directly to the underlying graphics context. Must be followed by a call to endNativePainting(). Only the states the underlying paint engine changes will be reset to their respective default states. These states may change in a new release of CopperSpice. The following states are currently reset in the OpenGL 2 engine.
If for example, the OpenGL polygon mode is changed by the user inside a beginNativePaint()/endNativePainting() block, it will not be reset to the default state by endNativePainting(). Here is an example that shows intermixing of painter commands and raw OpenGL commands:
Returns the bounding rectangle of the text as it will appear when drawn inside the given rect with the specified flags using the currently set font().
QRectF QPainter::boundingRect | ( | const QRectF & | rect, |
const QString & | text, | ||
const QTextOption & | option = QTextOption() |
||
) |
Instead of specifying flags as a bitwise OR of the Qt::AlignmentFlag and Qt::TextFlag, this method takes an option argument. The QTextOption class provides a description of rich text properties.
Returns the bounding rectangle of the text as it will appear when drawn inside the given rect with the specified flags using the currently set font(). This method indicates where the drawText() method will draw when given the same arguments. If the text does not fit within the given rectangle using the specified flags, the method returns the required rectangle.
The flags argument is a bitwise OR of the following flags. If several of the horizontal or several of the vertical alignment flags are set, the resulting alignment is undefined.
|
inline |
Returns the bounding rectangle of the given text as it will appear when drawn inside the rectangle beginning at the point (x, y) with width and height.
const QBrush & QPainter::brush | ( | ) | const |
Returns the painter's current brush.
QPoint QPainter::brushOrigin | ( | ) | const |
Returns the currently set brush origin.
QRectF QPainter::clipBoundingRect | ( | ) | const |
Returns the bounding rectangle of the current clip if there is a clip, otherwise returns an empty rectangle. The clip region is given in logical coordinates. The bounding rectangle is not guaranteed to be tight.
QPainterPath QPainter::clipPath | ( | ) | const |
Returns the current clip as a path. The clip path is given in logical coordinates.
QPainter does not store the combined clip explicitly as this is handled by the underlying QPaintEngine, so the path is recreated on demand and transformed to the current logical coordinate system. This is potentially an expensive operation.
QRegion QPainter::clipRegion | ( | ) | const |
Returns the currently set clip region. Note that the clip region is given in logical coordinates.
QPainter does not store the combined clip explicitly as this is handled by the underlying QPaintEngine, so the path is recreated on demand and transformed to the current logical coordinate system. This is potentially an expensive operation.
|
deprecated |
It is advisable to use combinedTransform() instead of this function to preserve the properties of perspective transformations.
QTransform QPainter::combinedTransform | ( | ) | const |
Returns the transformation matrix combining the current window/viewport and world transformation.
CompositionMode QPainter::compositionMode | ( | ) | const |
Returns the current composition mode.
QPaintDevice * QPainter::device | ( | ) | const |
Returns the paint device on which this painter is currently painting or nullptr if the painter is not active.
|
deprecated |
You should use deviceTransform() instead of this method to preserve the properties of perspective transformations. This method is only needed when using platform painting commands on the platform dependent handle (Qt::HANDLE), and the platform does not do transformations natively. The QPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.
const QTransform & QPainter::deviceTransform | ( | ) | const |
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.
This methods is only needed when using platform painting commands on the platform dependent handle (Qt::HANDLE), and the platform does not do transformations natively. The QPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.
|
inline |
Draws the arc defined by the given rect, startAngle, and arcLength.
void QPainter::drawArc | ( | const QRectF & | rect, |
int | startAngle, | ||
int | arcLength | ||
) |
Draws the arc defined by the given rect, startAngle, and arcLength.
The startAngle and spanAngle must be specified in 1/16th of a degree. For example, a full circle equals 5760 (16 * 360). Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.
|
inline |
Draws the arc defined by the rectangle beginning at (x, y) with the specified width and height, and the given startAngle and arcLength.
|
inline |
Draws the chord defined by the given rect, startAngle, and arcLength.
void QPainter::drawChord | ( | const QRectF & | rect, |
int | startAngle, | ||
int | arcLength | ||
) |
Draws the chord defined by the given rect, startAngle and arcLength. The chord is filled with the current brush(). The startAngle and arcLength must be specified in 1/16th of a degree. For example a full circle equals 5760 (16 * 360).
Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.
|
inline |
Draws the chord defined by the rectangle beginning at (x, y) with the specified width and height, and the given startAngle and arcLength.
void QPainter::drawConvexPolygon | ( | const QPoint * | points, |
int | pointCount | ||
) |
Draws a convex polygon defined by points starting at points for the given number of points specified in pointCount using the current pen.
void QPainter::drawConvexPolygon | ( | const QPointF * | points, |
int | pointCount | ||
) |
Draws a convex polygon defined by points starting at points for the given number of points specified in pointCount using the current pen.
The first point is implicitly connected to the last point, and the polygon is filled with the current brush(). If the supplied polygon is not convex, which means it contains at least one angle larger than 180 degrees, the results are undefined.
On some platforms such as X11 drawConvexPolygon() can be faster than using drawPolygon().
|
inline |
Draws the convex polygon defined by polygon using the current pen and brush.
|
inline |
Draws the convex polygon defined by polygon using the current pen and brush.
|
inline |
Draws the ellipse positioned at thegiven center point. The values for rx and ry specify the distance for each axis.
Draws the ellipse positioned at thegiven center point. The values for rx and ry specify the distance for each axis.
void QPainter::drawEllipse | ( | const QRect & | rect | ) |
Draws the ellipse defined by the given rect.
void QPainter::drawEllipse | ( | const QRectF & | rect | ) |
Draws the ellipse defined by the given rect. A filled ellipse has a size of rectangle.size(). A stroked ellipse has a size of rectangle.size() plus the pen width.
|
inline |
Draws the ellipse defined by the rectangle beginning at (x, y) with the given width and height.
Draws the specified glyphs at the given point. The position gives the edge of the baseline for the string of glyphs. The glyphs will be retrieved from the font selected by glyphs and at offsets given by the positions in glyphs.
Draws the given image at the given point.
|
inline |
Draws the rectangular portion sourceRect of the given image with its origin at the given point.
Draws the given image at the given point.
|
inline |
Draws the rectangular portion sourceRect of the given image with its origin at the given point.
Draws the given image into the given rect. The image is scaled to fit the rectangle, if the image and rectangle size do not match.
|
inline |
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device. The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
Draws the given image into the given rect. The image is scaled to fit the rectangle, if the image and rectangle size do not match.
void QPainter::drawImage | ( | const QRectF & | targetRect, |
const QImage & | image, | ||
const QRectF & | sourceRect, | ||
Qt::ImageConversionFlags | flags = Qt::AutoColor |
||
) |
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device. The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to specify how you would prefer this to happen.
|
inline |
Draws an image at (x, y) by copying a part of image into the paint device. The values for x and y specify the top-left point in the paint device that is to be drawn onto.
The values for (sx, sy) specify the top-left point in image that is to be drawn. The default is (0, 0).
The values for (sw, sh) specify the size of the image to be drawn. The default (0, 0) (and negative) means all the way to the bottom-right of the image.
|
inline |
Draws a line defined by line.
|
inline |
Draws a line from point1 to point2.
Draws a line from point1 to point2.
|
inline |
Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2).
void QPainter::drawLines | ( | const QLine * | lines, |
int | lineCount | ||
) |
Draws a list of lines starting at lines for the given number of lines, specified in lineCount using the current pen.
void QPainter::drawLines | ( | const QLineF * | lines, |
int | lineCount | ||
) |
Draws a list of lines starting at lines for the given number of lines, specified in lineCount using the current pen.
void QPainter::drawLines | ( | const QPoint * | points, |
int | lineCount | ||
) |
Draws the list of lines starting at points for the given number of lines, specified in lineCount using the current pen. The lines are specified as pairs of points so the number of entries in lines must be at least lineCount * 2.
void QPainter::drawLines | ( | const QPointF * | points, |
int | lineCount | ||
) |
Draws the list of lines starting at points for the given number of lines, specified in lineCount using the current pen. The lines are specified as pairs of points so the number of entries in lines must be at least lineCount * 2.
Draws the set of lines defined by line, using the current pen and brush.
Draws the set of lines defined by line using the current pen and brush.
Draws a line for each pair of points in the vector points using the current pen. If there is an odd number of points in the array, the last point will be ignored.
Draws a line for each pair of points in the vector points using the current pen. If there is an odd number of points in the array, the last point will be ignored.
void QPainter::drawPath | ( | const QPainterPath & | path | ) |
Draws the given painter path using the current pen for outline and the current brush for filling.
QPainterPath path;
path.moveTo(20, 80);
path.lineTo(20, 30);
path.cubicTo(80, 0, 50, 50, 80, 80);
QPainter painter(this);
painter.drawPath(path);
|
Replays the given picture at the given point.
Replays the given picture at the given point.
The QPicture class is a paint device that records and replays QPainter commands. A picture serializes the painter commands to an IO device in a platform-independent format. Everything that can be painted on a widget or pixmap can also be stored in a picture.
This function does exactly the same as QPicture::play() when called with point = QPoint(0, 0).
|
inline |
Draws the given picture at point (x, y).
|
inline |
Draws a pie defined by the given rect, startAngle, and arcLength.
void QPainter::drawPie | ( | const QRectF & | rect, |
int | startAngle, | ||
int | arcLength | ||
) |
Draws a pie defined by the given rect, startAngle, and arcLength. The pie is filled with the current brush().
The startAngle and arcLength must be specified in 1/16th of a degree. For example a full circle equals 5760 (16 * 360). Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.
|
inline |
Draws the pie defined by the rectangle beginning at (x, y) with the specified width and height, and the given startAngle and arcLength.
Draws the given pixmap with its origin at the given point.
|
inline |
Draws the rectangular portion sourceRect of the given pixmap with its origin at the given point.
Draws the given pixmap with its origin at the given point.
|
inline |
Draws the rectangular portion sourceRect of the given pixmap with its origin at the given point.
Draws the given pixmap into the given rect. The pixmap is scaled to fit the rectangle, if the pixmap and rectangle size do not match.
|
inline |
Draws the rectangular portion sourceRect of the given pixmap into the given targetRect in the paint device. The pixmap is scaled to fit the rectangle, if the pixmap and rectangle size do not match.
void QPainter::drawPixmap | ( | const QRectF & | targetRect, |
const QPixmap & | pixmap, | ||
const QRectF & | sourceRect | ||
) |
Draws the rectangular portion sourceRect of the given pixmap into the given targetRect in the paint device. The pixmap is scaled to fit the rectangle, if the pixmap and rectangle size do not match.
If pixmap is a QBitmap it is drawn with the bits that are "set" using the pen color. If backgroundMode is Qt::OpaqueMode, the "unset" bits are drawn using the color of the background brush. If backgroundMode is Qt::TransparentMode, the "unset" bits are transparent. Drawing bitmaps with gradient or texture colors is not supported.
|
inline |
Draws the given pixmap at position (x, y).
|
inline |
Draws a pixmap at (x, y) by copying a part of the given pixmap into the paint device.
The X and Y coordinates specify the top-left point in the paint device. The SX and SY coordinates specify the top-left point in the pixmap. The SW and SH coordinates specify the size of the pixmap.
|
inline |
Draws the pixmap in the rectangle at position (x, y) with the given width and height.
|
inline |
Draws the rectangular portion with the origin (sx, sy), width sw and height sh, of the given pixmap, at the point (x, y), with the given width and height. If SW or SH are equal to zero the width/height of the pixmap is used and adjusted by the offset sx/sy.
void QPainter::drawPixmapFragments | ( | const PixmapFragment * | fragments, |
int | fragmentCount, | ||
const QPixmap & | pixmap, | ||
PixmapFragmentHints | hints = PixmapFragmentHints() |
||
) |
Draws pixmap, or a sub-rectangle of pixmap, at multiple positions with different scale, rotation, and opacity. The value for fragments is an array of fragmentCount elements specifying the parameters used to draw each pixmap fragment. The hints parameter can be used to pass in drawing hints.
This method is potentially faster than multiple calls to drawPixmap() since the backend can optimize state changes.
|
inline |
Draws a single point at the given point using the current pen color.
|
inline |
Draws a single point at the given point using the current pen color.
|
inline |
Draws a single point at position (x, y).
void QPainter::drawPoints | ( | const QPoint * | points, |
int | pointCount | ||
) |
Draws points starting from points for the given number of points specified in pointCount.
void QPainter::drawPoints | ( | const QPointF * | points, |
int | pointCount | ||
) |
Draws points starting from points for the given number of points specified in pointCount.
|
inline |
Draws the points in the vector polygon.
|
inline |
Draws the points in the vector polygon.
void QPainter::drawPolygon | ( | const QPoint * | points, |
int | pointCount, | ||
Qt::FillRule | fillRule = Qt::OddEvenFill |
||
) |
Draws a polygon defined by points starting at points for the given number of points specified in pointCount using the given fillRule.
void QPainter::drawPolygon | ( | const QPointF * | points, |
int | pointCount, | ||
Qt::FillRule | fillRule = Qt::OddEvenFill |
||
) |
Draws a polygon defined by points starting at points for the given number of points specified in pointCount using the current pen and brush. The first point is implicitly connected to the last point and the polygon is filled with the current brush().
If fillRule is Qt::WindingFill, the polygon is filled using the winding fill algorithm. If fillRule is Qt::OddEvenFill, the polygon is filled using the odd-even fill algorithm. Refer to Qt::FillRule for a detailed description of these fill rules.
|
inline |
Draws a polygon defined by the given polygon using the given fillRule.
|
inline |
Draws a polygon defined by the given polygon using the given fillRule.
void QPainter::drawPolyline | ( | const QPoint * | points, |
int | pointCount | ||
) |
Draws the polyline defined by points starting at points for the given number of points specified in pointCount using the current pen.
void QPainter::drawPolyline | ( | const QPointF * | points, |
int | pointCount | ||
) |
Draws the polyline defined by points starting at points for the given number of points specified in pointCount using the current pen. The last point is not connected to the first, neither is the polyline filled.
|
inline |
Draws the polyline defined by the given polygon using the current pen.
|
inline |
Draws the polyline defined by the given polygon using the current pen.
|
inline |
Draws the given rect with the current pen and brush.
|
inline |
Draws the given rect with the current pen and brush. A filled rectangle has a size of rect.size(). A stroked rectangle has a size of rect.size() plus the pen width.
|
inline |
Draws a rectangle with the upper left corner at (x, y) and the given width and height.
void QPainter::drawRects | ( | const QRect * | rects, |
int | rectCount | ||
) |
Draws rectangles starting from rects for the given number of rectangles specified in rectCount using the current pen and brush.
void QPainter::drawRects | ( | const QRectF * | rects, |
int | rectCount | ||
) |
Draws rectangles starting from rects for the given number of rectangles specified in rectCount using the current pen and brush.
Draws the given rectangles using the current pen and brush.
Draws the given rectangles using the current pen and brush.
|
inline |
Draws the given rect with rounded corners.
The xRadius and yRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. When mode is Qt::RelativeSize then xRadius and yRadius are specified in percentage of half the rectangle's width and height respectively and should be in the range 0.0 to 100.0.
A filled rectangle has a size of rect.size(). A stroked rectangle has a size of rect.size() plus the pen width.
void QPainter::drawRoundedRect | ( | const QRectF & | rect, |
qreal | xRadius, | ||
qreal | yRadius, | ||
Qt::SizeMode | mode = Qt::AbsoluteSize |
||
) |
Draws the given rect with rounded corners.
The xRadius and yRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. When mode is Qt::RelativeSize then xRadius and yRadius are specified in percentage of half the rectangle's width and height respectively and should be in the range 0.0 to 100.0.
A filled rectangle has a size of rect.size(). A stroked rectangle has a size of rect.size() plus the pen width.
QRectF rectangle(10.0, 20.0, 80.0, 60.0);
QPainter painter(this);
painter.drawRoundedRect(rectangle, 20.0, 15.0);
|
|
inline |
Draws a rectangle using x, y, width, height with rounded corners.
The xRadius and yRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. When mode is Qt::RelativeSize then xRadius and yRadius are specified in percentage of half the rectangle's width and height respectively and should be in the range 0.0 to 100.0.
A filled rectangle has a size of (width, height). A stroked rectangle has a size of (width, height) plus the pen width.
|
inlinedeprecated |
|
deprecated |
The xRound and yRound arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness. A filled rectangle has a size of rectangle.size(). A stroked rectangle has a size of rectangle.size() plus the pen width.
|
inlinedeprecated |
|
inline |
Draws the staticText at the topLeftPosition.
If the painter's transformation is not affine then staticText will be drawn using regular calls to drawText(). The y-position is used as the top of the font.
void QPainter::drawStaticText | ( | const QPointF & | topLeftPosition, |
const QStaticText & | staticText | ||
) |
Draws the given staticText at the given topLeftPosition.
The text will be drawn using the font and the transformation set on the painter. If the font and/or transformation set on the painter are different from the ones used to initialize the layout of the QStaticText, then the layout will have to be recalculated. Use QStaticText::prepare() to initialize staticText with the font and transformation with which it will later be drawn.
If topLeftPosition is not the same as when staticText was initialized, or when it was last drawn, then there will be a slight overhead when translating the text to its new position.
If the painter's transformation is not affine then staticText will be drawn using regular calls to drawText(). The y-position is used as the top of the font.
|
inline |
Draws the staticText at coordinates left and top.
If the painter's transformation is not affine then staticText will be drawn using regular calls to drawText(). The y-position is used as the top of the font.
Draws the given text with the currently defined text direction, beginning at the given point. By default, QPainter draws text anti-aliased.
The y-position is used as the baseline of the font.
Draws the given text with the currently defined text direction, beginning at the given point.
This function does not handle the newline character (\n), as it can not break text into multiple lines, and it can not display the newline character. Use the QPainter::drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.
By default QPainter draws text anti-aliased. The y-position is used as the baseline of the font.
void QPainter::drawText | ( | const QRect & | rect, |
int | flags, | ||
const QString & | text, | ||
QRect * | boundingRect = nullptr |
||
) |
Draws the given text within the provided rect according to the specified flags. The boundingRect (if not null) is set to the what the bounding rectangle should be in order to enclose the whole text.
By default QPainter draws text anti-aliased. The y-coordinate of the rectangle is used as the top of the font.
void QPainter::drawText | ( | const QRectF & | rect, |
const QString & | text, | ||
const QTextOption & | option = QTextOption() |
||
) |
Draws the given text in the rect specified using the option to control its positioning and orientation.
By default QPainter draws text anti-aliased. The y-coordinate of rectangle is used as the top of the font.
void QPainter::drawText | ( | const QRectF & | rect, |
int | flags, | ||
const QString & | text, | ||
QRectF * | boundingRect = nullptr |
||
) |
Draws the given text within the provided rect.
The boundingRect (if not null) is set to the what the bounding rectangle should be in order to enclose the whole text. The flags argument is a bitwise OR of the following flags.
By default QPainter draws text anti-aliased. The y-coordinate of the rectangle is used as the top of the font.
|
inline |
Draws the given text at position (x, y), using the painter's currently defined text direction.
By default, QPainter draws text anti-aliased. The y-position is used as the baseline of the font.
|
inline |
Draws the given text within the rectangle with origin (x, y), width and height. The boundingRect (if not null) is set to the actual bounding rectangle of the output. The flags argument is a bitwise OR of the following flags.
By default, QPainter draws text anti-aliased. The y-position is used as the top of the font.
|
inline |
Draws a tiled pixmap inside the given rect with its origin at the given point.
void QPainter::drawTiledPixmap | ( | const QRectF & | rect, |
const QPixmap & | pixmap, | ||
const QPointF & | point = QPointF() |
||
) |
Draws a tiled pixmap inside the given rect with its origin at the given point.
Calling drawTiledPixmap() is similar to calling drawPixmap() several times to fill (tile) an area with a pixmap, but is potentially much more efficient depending on the underlying window system.
|
inline |
Draws a tiled pixmap in the specified rectangle.
The (x, y) coordinates specify the top-left point in the paint device. The size is specified by the width and height. The (sx, sy) coordinates specify the top-left point in the given pixmap.
bool QPainter::end | ( | ) |
Ends the painting process. Any resources used while painting are released. You do not normally need to call this since it is called by the destructor. Returns true if the painter is no longer active, otherwise returns false.
void QPainter::endNativePainting | ( | ) |
Restores the painter after manually issuing native painting commands. Lets the painter restore any native state that it relies on before calling any other painter commands.
|
inline |
Erases the area inside the given rect.
void QPainter::eraseRect | ( | const QRectF & | rect | ) |
Erases the area inside the given rect. Equivalent to calling fillRect(rectangle, background())
|
inline |
Erases the area inside the rectangle beginning at (x, y) with the given width and height.
void QPainter::fillPath | ( | const QPainterPath & | path, |
const QBrush & | brush | ||
) |
Fills the given path using the brush. The outline is not drawn. Alternatively, you can specify a QColor instead of a QBrush. The QBrush constructor will automatically create a solid pattern brush.
Fills the given rect with the specified brush.
Fills the given rect with the specified color.
|
inline |
Fills the given rect with the brush style specified.
|
inline |
Fills the given rect with the specified color.
Fills the given rect using the brush. Alternatively, you can specify a QColor instead of a QBrush. The QBrush constructor will automatically create a solid pattern brush.
Fills the given rect with the specified color.
|
inline |
Fills the given rect with the brush specified style.
|
inline |
Fills the given rect with the specified color.
|
inline |
Fills the rectangle beginning at (x, y) with the given width and height, using the brush.
|
inline |
Fills the rectangle beginning at (x, y) with the given width and height, using the color.
|
inline |
Fills the rectangle beginning at (x, y) with the given width and height, using the brush style specified.
|
inline |
Fills the rectangle beginning at (x, y) with the given width and height, using the color.
const QFont & QPainter::font | ( | ) | const |
Returns the currently set font used for drawing text.
QFontInfo QPainter::fontInfo | ( | ) | const |
Returns the font info for the painter if the painter is active. Otherwise, the return value is undefined.
QFontMetrics QPainter::fontMetrics | ( | ) | const |
Returns the font metrics for the painter if the painter is active. Otherwise, the return value is undefined.
bool QPainter::hasClipping | ( | ) | const |
Returns true if clipping has been set, otherwise returns false.
void QPainter::initFrom | ( | const QPaintDevice * | device | ) |
bool QPainter::isActive | ( | ) | const |
Returns true if begin() has been called and end() has not yet been called, otherwise returns false.
Qt::LayoutDirection QPainter::layoutDirection | ( | ) | const |
Returns the layout direction used by the painter when drawing text.
|
deprecated |
|
deprecated |
qreal QPainter::opacity | ( | ) | const |
Returns the opacity of the painter. The default value is 1.
QPaintEngine * QPainter::paintEngine | ( | ) | const |
Returns the paint engine that the painter is currently operating on if the painter is active, otherwise 0.
|
deprecatedstatic |
Returns the replacement for given device. The optional out parameter point returns the offset within the replaced device.
Making use of redirections in the QPainter API implies that QPainter::begin() and QPaintDevice destructors need to hold a mutex for a short period. This can impact performance. Use of QWidget::render is strongly encouraged.
RenderHints QPainter::renderHints | ( | ) | const |
Returns a flag that specifies the rendering hints that are set for this painter.
|
deprecated |
It is advisable to use resetTransform() instead of this method to preserve the properties of perspective transformations.
void QPainter::resetTransform | ( | ) |
Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldTransform(), setViewport() and setWindow().
void QPainter::restore | ( | ) |
Restores the current painter state (pops a saved state off the stack).
|
deprecatedstatic |
Restores the previous redirection for the given device after a call to setRedirected().
Making use of redirections in the QPainter API implies that QPainter::begin() and QPaintDevice destructors need to hold a mutex for a short period. This can impact performance. Use of QWidget::render is strongly encouraged.
void QPainter::rotate | ( | qreal | angle | ) |
Rotates the coordinate system the given angle clockwise.
void QPainter::save | ( | ) |
Scales the coordinate system by (sx, sy).
void QPainter::setBackground | ( | const QBrush & | brush | ) |
Sets the background brush of the painter to the given brush.
The background brush is the brush that is filled in when drawing opaque text, stippled lines and bitmaps. The background brush has no effect in transparent background mode (which is the default).
void QPainter::setBackgroundMode | ( | Qt::BGMode | mode | ) |
Sets the background mode of the painter to the given mode.
Qt::TransparentMode (the default) draws stippled lines and text without setting the background pixels. Qt::OpaqueMode fills these space with the current background color.
In order to draw a bitmap or pixmap transparently, you must use QPixmap::setMask().
void QPainter::setBrush | ( | const QBrush & | brush | ) |
Sets the painter's brush to the given brush. The painter's brush defines how shapes are filled.
void QPainter::setBrush | ( | Qt::BrushStyle | style | ) |
Sets the painter's brush to black color and the specified style.
|
inline |
Sets the brush's origin to the given point.
void QPainter::setBrushOrigin | ( | const QPointF & | point | ) |
Sets the brush origin to point. The brush origin specifies the (0, 0) coordinate of the painter's brush.
|
inline |
Sets the brush's origin to point (x, y).
void QPainter::setClipPath | ( | const QPainterPath & | path, |
Qt::ClipOperation | operation = Qt::ReplaceClip |
||
) |
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation. The clip path is specified in logical (painter) coordinates.
void QPainter::setClipping | ( | bool | enable | ) |
Enables clipping if enable is true, otherwise disables clipping.
void QPainter::setClipRect | ( | const QRect & | rect, |
Qt::ClipOperation | operation = Qt::ReplaceClip |
||
) |
Enables clipping, and sets the clip region to the given rect using the given clip operation.
void QPainter::setClipRect | ( | const QRectF & | rect, |
Qt::ClipOperation | operation = Qt::ReplaceClip |
||
) |
Enables clipping, and sets the clip region to the given rect using the given clip operation. The default operation is to replace the current clip rectangle.
The clip rectangle is specified in logical (painter) coordinates.
|
inline |
Enables clipping, and sets the clip region to the rectangle beginning at (x, y) with the given width and height.
void QPainter::setClipRegion | ( | const QRegion & | region, |
Qt::ClipOperation | operation = Qt::ReplaceClip |
||
) |
Sets the clip region to the given region using the specified clip operation. The default clip operation is to replace the current clip region. The clip region is given in logical coordinates.
void QPainter::setCompositionMode | ( | CompositionMode | mode | ) |
Sets the composition mode to the given mode.
void QPainter::setFont | ( | const QFont & | font | ) |
Sets the painter's font to the given font. This font is used by subsequent drawText() methods. The text color is the same as the pen color.
If you set a font that is not available, CopperSpice finds a close match. font() will return what you set using setFont() and fontInfo() returns the font actually being used (which may be the same).
void QPainter::setLayoutDirection | ( | Qt::LayoutDirection | direction | ) |
Sets the layout direction used by the painter when drawing text to the specified direction. The default is Qt::LayoutDirectionAuto, which will implicitly determine the direction from the text drawn.
|
deprecated |
|
deprecated |
void QPainter::setOpacity | ( | qreal | opacity | ) |
Sets the opacity of the painter to opacity. The value should be in the range 0.0 to 1.0, where 0.0 is fully transparent and 1.0 is fully opaque. Opacity set on the painter will apply to all drawing operations individually.
void QPainter::setPen | ( | const QColor & | color | ) |
Sets the painter's pen to have style Qt::SolidLine, width 0 and the specified color.
void QPainter::setPen | ( | const QPen & | pen | ) |
Sets the painter's pen to be the given pen. The pen defines how to draw lines and outlines, and it also defines the text color.
void QPainter::setPen | ( | Qt::PenStyle | style | ) |
Sets the painter's pen to have the given style, width 0 and black color.
|
deprecatedstatic |
Redirects all paint commands for the given paint device, to the replacement device. The optional point point defines an offset within the source device.
The redirection will not be effective until the begin() function has been called; make sure to call end() for the given device's painter (if any) before redirecting. Call restoreRedirected() to restore the previous redirection.
Making use of redirections in the QPainter API implies that QPainter::begin() and QPaintDevice destructors need to hold a mutex for a short period. This can impact performance.
void QPainter::setRenderHint | ( | RenderHint | hint, |
bool | on = true |
||
) |
Sets the given render hint on the painter if on is true, otherwise clears the render hint.
void QPainter::setRenderHints | ( | RenderHints | hints, |
bool | on = true |
||
) |
Sets the given render hints on the painter if on is true, otherwise clears the render hints.
void QPainter::setTransform | ( | const QTransform & | transform, |
bool | combine = false |
||
) |
Sets the world transformation matrix. If combine is true the specified transform is combined with the current matrix, otherwise it replaces the current matrix.
void QPainter::setViewport | ( | const QRect & | viewport | ) |
Sets the painter's viewport rectangle to the given viewport and enables view transformations.
The viewport rectangle is part of the view transformation. The viewport specifies the device coordinate system. The window(), specifies the logical coordinate system.
The default viewport rectangle is the same as the device's rectangle.
|
inline |
Sets the painter's viewport rectangle to be the rectangle beginning at (x, y) with the given width and height.
void QPainter::setViewTransformEnabled | ( | bool | enable | ) |
Enables view transformations if enable is true, or disables view transformations if enable is false.
void QPainter::setWindow | ( | const QRect & | window | ) |
Sets the painter's window to the given window, and enables view transformations. The window rectangle is part of the view transformation. The window specifies the logical coordinate system. The viewport() specifies the device coordinate system.
The default window rectangle is the same as the device's rectangle.
|
inline |
Sets the painter's window to the rectangle beginning at (x, y) and the given width and height.
|
deprecated |
If combine is true then the matrix is combined with the current transformation matrix. Otherwise matrix replaces the current transformation matrix. If matrix is the identity matrix and combine is false, this method calls setWorldMatrixEnabled(false).
The identity matrix is the matrix where QMatrix::m11() and QMatrix::m22() are 1.0 and the rest are 0.0.
The following methods can transform the coordinate system without using a QMatrix.
These four methods operate on the painter's worldMatrix() and are implemented as shown below.
When drawing on a QPicture the value for combine must be true.
void QPainter::setWorldMatrixEnabled | ( | bool | enable | ) |
Enables transformations if enable is true, otherwise transformations are disabled. The world transformation matrix is not changed.
void QPainter::setWorldTransform | ( | const QTransform & | matrix, |
bool | combine = false |
||
) |
Sets the world transformation matrix. If combine is true, the specified matrix is combined with the current matrix, otherwise it replaces the current matrix.
Shears the coordinate system by (sh, sv).
void QPainter::strokePath | ( | const QPainterPath & | path, |
const QPen & | pen | ||
) |
Draws the outline path with the pen specified by pen.
|
inline |
Returns true if hint is set, otherwise returns false.
const QTransform & QPainter::transform | ( | ) | const |
Returns the world transformation matrix.
|
inline |
Translates the coordinate system by the given offset.
void QPainter::translate | ( | const QPointF & | offset | ) |
Translates the coordinate system by the given offset.
Translates the coordinate system by the vector (dx, dy).
QRect QPainter::viewport | ( | ) | const |
Returns the viewport rectangle.
bool QPainter::viewTransformEnabled | ( | ) | const |
Returns true if view transformation is enabled, otherwise returns false.
QRect QPainter::window | ( | ) | const |
Returns the window rectangle.
|
deprecated |
It is advisable to use worldTransform() because worldMatrix() does not preserve the properties of perspective transformations.
bool QPainter::worldMatrixEnabled | ( | ) | const |
Returns true if world transformation is enabled, otherwise returns false.
const QTransform & QPainter::worldTransform | ( | ) | const |
Returns the world transformation matrix.