Qt 4.8
Classes | Public Types | Public Functions | Static Public Functions | Properties | Friends | List of all members
QPainter Class Reference

The QPainter class performs low-level painting on widgets and other paint devices. More...

#include <qpainter.h>

Inheritance diagram for QPainter:
QStylePainter

Classes

class  PixmapFragment
 This class is used in conjunction with the QPainter::drawPixmapFragments() function to specify how a pixmap, or sub-rect of a pixmap, is drawn. More...
 

Public Types

enum  CompositionMode {
  CompositionMode_SourceOver, CompositionMode_DestinationOver, CompositionMode_Clear, CompositionMode_Source,
  CompositionMode_Destination, CompositionMode_SourceIn, CompositionMode_DestinationIn, CompositionMode_SourceOut,
  CompositionMode_DestinationOut, CompositionMode_SourceAtop, CompositionMode_DestinationAtop, CompositionMode_Xor,
  CompositionMode_Plus, CompositionMode_Multiply, CompositionMode_Screen, CompositionMode_Overlay,
  CompositionMode_Darken, CompositionMode_Lighten, CompositionMode_ColorDodge, CompositionMode_ColorBurn,
  CompositionMode_HardLight, CompositionMode_SoftLight, CompositionMode_Difference, CompositionMode_Exclusion,
  RasterOp_SourceOrDestination, RasterOp_SourceAndDestination, RasterOp_SourceXorDestination, RasterOp_NotSourceAndNotDestination,
  RasterOp_NotSourceOrNotDestination, RasterOp_NotSourceXorDestination, RasterOp_NotSource, RasterOp_NotSourceAndDestination,
  RasterOp_SourceAndNotDestination
}
 Defines the modes supported for digital image compositing. More...
 
enum  PixmapFragmentHint { OpaqueHint = 0x01 }
 
enum  RenderHint {
  Antialiasing = 0x01, TextAntialiasing = 0x02, SmoothPixmapTransform = 0x04, HighQualityAntialiasing = 0x08,
  NonCosmeticDefaultPen = 0x10
}
 Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine. More...
 

Public Functions

const QBrushbackground () const
 Returns the current background brush. More...
 
Qt::BGMode backgroundMode () const
 Returns the current background mode. More...
 
bool begin (QPaintDevice *)
 Begins painting the paint device and returns true if successful; otherwise returns false. More...
 
void beginNativePainting ()
 Flushes the painting pipeline and prepares for the user issuing commands directly to the underlying graphics context. More...
 
QRectF boundingRect (const QRectF &rect, int flags, const QString &text)
 Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle with the specified flags using the currently set font(); i. More...
 
QRect boundingRect (const QRect &rect, int flags, const QString &text)
 Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle with the specified flags using the currently set font(). More...
 
QRect boundingRect (int x, int y, int w, int h, int flags, const QString &text)
 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 w and height h. More...
 
QRectF boundingRect (const QRectF &rect, const QString &text, const QTextOption &o=QTextOption())
 Instead of specifying flags as a bitwise OR of the Qt::AlignmentFlag and Qt::TextFlag, this overloaded function takes an option argument. More...
 
const QBrushbrush () const
 Returns the painter's current brush. More...
 
QPoint brushOrigin () const
 Returns the currently set brush origin. More...
 
QRectF clipBoundingRect () const
 Returns the bounding rectangle of the current clip if there is a clip; otherwise returns an empty rectangle. More...
 
QPainterPath clipPath () const
 Returns the currently clip as a path. More...
 
QRegion clipRegion () const
 Returns the currently set clip region. More...
 
QMatrix combinedMatrix () const
 Returns the transformation matrix combining the current window/viewport and world transformation. More...
 
QTransform combinedTransform () const
 Returns the transformation matrix combining the current window/viewport and world transformation. More...
 
CompositionMode compositionMode () const
 Returns the current composition mode. More...
 
QPaintDevicedevice () const
 Returns the paint device on which this painter is currently painting, or 0 if the painter is not active. More...
 
const QMatrixdeviceMatrix () const
 Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device. More...
 
const QTransformdeviceTransform () const
 Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device. More...
 
void drawArc (const QRectF &rect, int a, int alen)
 Draws the arc defined by the given rectangle, startAngle and spanAngle. More...
 
void drawArc (const QRect &, int a, int alen)
 Draws the arc defined by the given rectangle, startAngle and spanAngle. More...
 
void drawArc (int x, int y, int w, int h, int a, int alen)
 Draws the arc defined by the rectangle beginning at (x, y) with the specified width and height, and the given startAngle and spanAngle. More...
 
void drawChord (const QRectF &rect, int a, int alen)
 Draws the chord defined by the given rectangle, startAngle and spanAngle. More...
 
void drawChord (int x, int y, int w, int h, int a, int alen)
 Draws the chord defined by the rectangle beginning at (x, y) with the specified width and height, and the given startAngle and spanAngle. More...
 
void drawChord (const QRect &, int a, int alen)
 Draws the chord defined by the given rectangle, startAngle and spanAngle. More...
 
void drawConvexPolygon (const QPointF *points, int pointCount)
 Draws the convex polygon defined by the first pointCount points in the array points using the current pen. More...
 
void drawConvexPolygon (const QPolygonF &polygon)
 Draws the convex polygon defined by polygon using the current pen and brush. More...
 
void drawConvexPolygon (const QPoint *points, int pointCount)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the convex polygon defined by the first pointCount points in the array points using the current pen. More...
 
void drawConvexPolygon (const QPolygon &polygon)
 Draws the convex polygon defined by polygon using the current pen and brush. More...
 
void drawEllipse (const QRectF &r)
 Draws the ellipse defined by the given rectangle. More...
 
void drawEllipse (const QRect &r)
 Draws the ellipse defined by the given rectangle. More...
 
void drawEllipse (int x, int y, int w, int h)
 Draws the ellipse defined by the rectangle beginning at ({x}, {y}) with the given width and height. More...
 
void drawEllipse (const QPointF &center, qreal rx, qreal ry)
 Draws the ellipse positioned at {center} with radii {rx} and {ry}. More...
 
void drawEllipse (const QPoint &center, int rx, int ry)
 Draws the ellipse positioned at {center} with radii {rx} and {ry}. More...
 
void drawGlyphRun (const QPointF &position, const QGlyphRun &glyphRun)
 Draws the specified glyphs at the given position. More...
 
void drawImage (const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
void drawImage (const QRect &targetRect, const QImage &image, const QRect &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
void drawImage (const QPointF &p, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
void drawImage (const QPoint &p, const QImage &image, const QRect &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
void drawImage (const QRectF &r, const QImage &image)
 Draws the given image into the given rectangle. More...
 
void drawImage (const QRect &r, const QImage &image)
 Draws the given image into the given rectangle. More...
 
void drawImage (const QPointF &p, const QImage &image)
 Draws the given image at the given point. More...
 
void drawImage (const QPoint &p, const QImage &image)
 Draws the given image at the given point. More...
 
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 QLineF &line)
 Draws a line defined by line. More...
 
void drawLine (const QLine &line)
 Draws a line defined by line. More...
 
void drawLine (int x1, int y1, int x2, int y2)
 Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2). More...
 
void drawLine (const QPoint &p1, const QPoint &p2)
 Draws a line from p1 to p2. More...
 
void drawLine (const QPointF &p1, const QPointF &p2)
 Draws a line from p1 to p2. More...
 
void drawLines (const QLineF *lines, int lineCount)
 Draws the first lineCount lines in the array lines using the current pen. More...
 
void drawLines (const QVector< QLineF > &lines)
 Draws the set of lines defined by the list lines using the current pen and brush. More...
 
void drawLines (const QPointF *pointPairs, int lineCount)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the first lineCount lines in the array pointPairs using the current pen. More...
 
void drawLines (const QVector< QPointF > &pointPairs)
 Draws a line for each pair of points in the vector pointPairs using the current pen. More...
 
void drawLines (const QLine *lines, int lineCount)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the first lineCount lines in the array lines using the current pen. More...
 
void drawLines (const QVector< QLine > &lines)
 Draws the set of lines defined by the list lines using the current pen and brush. More...
 
void drawLines (const QPoint *pointPairs, int lineCount)
 Draws the first lineCount lines in the array pointPairs using the current pen. More...
 
void drawLines (const QVector< QPoint > &pointPairs)
 Draws a line for each pair of points in the vector pointPairs using the current pen. More...
 
void drawPath (const QPainterPath &path)
 Draws the given painter path using the current pen for outline and the current brush for filling. More...
 
void drawPicture (const QPointF &p, const QPicture &picture)
 Replays the given picture at the given point. More...
 
void drawPicture (int x, int y, const QPicture &picture)
 Draws the given picture at point (x, y). More...
 
void drawPicture (const QPoint &p, const QPicture &picture)
 Replays the given picture at the given point. More...
 
void drawPie (const QRectF &rect, int a, int alen)
 Draws a pie defined by the given rectangle, startAngle and and spanAngle. More...
 
void drawPie (int x, int y, int w, int h, int a, int alen)
 
void drawPie (const QRect &, int a, int alen)
 Draws a pie defined by the given rectangle, startAngle and and spanAngle. More...
 
void drawPixmap (const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
 Draws the rectangular portion source of the given pixmap into the given target in the paint device. More...
 
void drawPixmap (const QRect &targetRect, const QPixmap &pixmap, const QRect &sourceRect)
 Draws the rectangular portion source of the given pixmap into the given target in the paint device. More...
 
void drawPixmap (int x, int y, int w, int h, const QPixmap &pm, int sx, int sy, int sw, int sh)
 Draws the rectangular portion with the origin ({sx}, {sy}), width sw and height sh, of the given pixmap , at the point ({x}, {y}), with a width of w and a height of h. More...
 
void drawPixmap (int x, int y, const QPixmap &pm, int sx, int sy, int sw, int sh)
 Draws a pixmap at ({x}, {y}) by copying a part of the given pixmap into the paint device. More...
 
void drawPixmap (const QPointF &p, const QPixmap &pm, const QRectF &sr)
 Draws the rectangular portion source of the given pixmap with its origin at the given point. More...
 
void drawPixmap (const QPoint &p, const QPixmap &pm, const QRect &sr)
 Draws the rectangular portion source of the given pixmap with its origin at the given point. More...
 
void drawPixmap (const QPointF &p, const QPixmap &pm)
 Draws the given pixmap with its origin at the given point. More...
 
void drawPixmap (const QPoint &p, const QPixmap &pm)
 Draws the given pixmap with its origin at the given point. More...
 
void drawPixmap (int x, int y, const QPixmap &pm)
 Draws the given pixmap at position ({x}, {y}). More...
 
void drawPixmap (const QRect &r, const QPixmap &pm)
 Draws the given pixmap into the given rectangle. More...
 
void drawPixmap (int x, int y, int w, int h, const QPixmap &pm)
 Draws the pixmap into the rectangle at position ({x}, {y}) with the given width and height. More...
 
void drawPixmapFragments (const PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, PixmapFragmentHints hints=0)
 This function is used to draw pixmap, or a sub-rectangle of pixmap, at multiple positions with different scale, rotation and opacity. More...
 
void drawPixmapFragments (const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount, const QPixmap &pixmap, PixmapFragmentHints hints=0)
 This function is used to draw the same pixmap with multiple target and source rectangles specified by targetRects. More...
 
void drawPoint (const QPointF &pt)
 Draws a single point at the given position using the current pen's color. More...
 
void drawPoint (const QPoint &p)
 Draws a single point at the given position using the current pen's color. More...
 
void drawPoint (int x, int y)
 Draws a single point at position (x, y). More...
 
void drawPoints (const QPointF *points, int pointCount)
 Draws the first pointCount points in the array points using the current pen's color. More...
 
void drawPoints (const QPolygonF &points)
 Draws the points in the vector points. More...
 
void drawPoints (const QPoint *points, int pointCount)
 Draws the first pointCount points in the array points using the current pen's color. More...
 
void drawPoints (const QPolygon &points)
 Draws the points in the vector points. More...
 
void drawPolygon (const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
 Draws the polygon defined by the first pointCount points in the array points using the current pen and brush. More...
 
void drawPolygon (const QPolygonF &polygon, Qt::FillRule fillRule=Qt::OddEvenFill)
 Draws the polygon defined by the given points using the fill rule fillRule. More...
 
void drawPolygon (const QPoint *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
 Draws the polygon defined by the first pointCount points in the array points. More...
 
void drawPolygon (const QPolygon &polygon, Qt::FillRule fillRule=Qt::OddEvenFill)
 Draws the polygon defined by the given points using the fill rule fillRule. More...
 
void drawPolyline (const QPointF *points, int pointCount)
 Draws the polyline defined by the first pointCount points in points using the current pen. More...
 
void drawPolyline (const QPolygonF &polyline)
 Draws the polyline defined by the given points using the current pen. More...
 
void drawPolyline (const QPoint *points, int pointCount)
 Draws the polyline defined by the first pointCount points in points using the current pen. More...
 
void drawPolyline (const QPolygon &polygon)
 Draws the polyline defined by the given points using the current pen. More...
 
void drawRect (const QRectF &rect)
 Draws the current rectangle with the current pen and brush. More...
 
void drawRect (int x1, int y1, int w, int h)
 Draws a rectangle with upper left corner at ({x}, {y}) and with the given width and height. More...
 
void drawRect (const QRect &rect)
 Draws the current rectangle with the current pen and brush. More...
 
void drawRects (const QRectF *rects, int rectCount)
 Draws the first rectCount of the given rectangles using the current pen and brush. More...
 
void drawRects (const QVector< QRectF > &rectangles)
 Draws the given rectangles using the current pen and brush. More...
 
void drawRects (const QRect *rects, int rectCount)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the first rectCount of the given rectangles using the current pen and brush. More...
 
void drawRects (const QVector< QRect > &rectangles)
 Draws the given rectangles using the current pen and brush. More...
 
void drawRoundedRect (const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
 Draws the given rectangle rect with rounded corners. More...
 
void drawRoundedRect (int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
 
void drawRoundedRect (const QRect &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
 
void drawRoundRect (const QRectF &r, int xround=25, int yround=25)
 Draws a rectangle r with rounded corners. More...
 
void drawRoundRect (int x, int y, int w, int h, int=25, int=25)
 Draws the rectangle x, y, w, h with rounded corners. More...
 
void drawRoundRect (const QRect &r, int xround=25, int yround=25)
 Draws the rectangle r with rounded corners. More...
 
void drawStaticText (const QPointF &topLeftPosition, const QStaticText &staticText)
 Draws the given staticText at the given topLeftPosition. More...
 
void drawStaticText (const QPoint &topLeftPosition, const QStaticText &staticText)
 Draws the staticText at the topLeftPosition. More...
 
void drawStaticText (int left, int top, const QStaticText &staticText)
 Draws the staticText at coordinates left and top. More...
 
void drawText (const QPointF &p, const QString &s)
 Draws the given text with the currently defined text direction, beginning at the given position. More...
 
void drawText (const QPoint &p, const QString &s)
 Draws the given text with the currently defined text direction, beginning at the given position. More...
 
void drawText (int x, int y, const QString &s)
 Draws the given text at position ({x}, {y}), using the painter's currently defined text direction. More...
 
void drawText (const QPointF &p, const QString &str, int tf, int justificationPadding)
 
void drawText (const QRectF &r, int flags, const QString &text, QRectF *br=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the given text within the provided rectangle. More...
 
void drawText (const QRect &r, int flags, const QString &text, QRect *br=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the given text within the provided rectangle according to the specified flags. More...
 
void drawText (int x, int y, int w, int h, int flags, const QString &text, QRect *br=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the given text within the rectangle with origin ({x}, {y}), width and height. More...
 
void drawText (const QRectF &r, const QString &text, const QTextOption &o=QTextOption())
 Draws the given text in the rectangle specified using the option to control its positioning and orientation. More...
 
void drawTextItem (const QPointF &p, const QTextItem &ti)
 Draws the text item ti at position p. More...
 
void drawTextItem (int x, int y, const QTextItem &ti)
 
void drawTextItem (const QPoint &p, const QTextItem &ti)
 Draws the text item ti at position p. More...
 
void drawTiledPixmap (const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
 Draws a tiled pixmap, inside the given rectangle with its origin at the given position. More...
 
void drawTiledPixmap (int x, int y, int w, int h, const QPixmap &, int sx=0, int sy=0)
 
void drawTiledPixmap (const QRect &, const QPixmap &, const QPoint &=QPoint())
 Draws a tiled pixmap, inside the given rectangle with its origin at the given position. More...
 
bool end ()
 Ends painting. More...
 
void endNativePainting ()
 Restores the painter after manually issuing native painting commands. More...
 
void eraseRect (const QRectF &)
 Erases the area inside the given rectangle. More...
 
void eraseRect (int x, int y, int w, int h)
 Erases the area inside the rectangle beginning at (x, y) with the given width and height. More...
 
void eraseRect (const QRect &)
 Erases the area inside the given rectangle. More...
 
void fillPath (const QPainterPath &path, const QBrush &brush)
 Fills the given path using the given brush. More...
 
void fillRect (const QRectF &, const QBrush &)
 Fills the given rectangle with the brush specified. More...
 
void fillRect (int x, int y, int w, int h, const QBrush &)
 Fills the rectangle beginning at ({x}, {y}) with the given width and height, using the given brush. More...
 
void fillRect (const QRect &, const QBrush &)
 Fills the given rectangle with the specified brush. More...
 
void fillRect (const QRectF &, const QColor &color)
 Fills the given rectangle with the color specified. More...
 
void fillRect (int x, int y, int w, int h, const QColor &color)
 Fills the rectangle beginning at ({x}, {y}) with the given width and height, using the given color. More...
 
void fillRect (const QRect &, const QColor &color)
 Fills the given rectangle with the color specified. More...
 
void fillRect (int x, int y, int w, int h, Qt::GlobalColor c)
 Fills the rectangle beginning at ({x}, {y}) with the given width and height, using the given color. More...
 
void fillRect (const QRect &r, Qt::GlobalColor c)
 Fills the given rectangle with the specified color. More...
 
void fillRect (const QRectF &r, Qt::GlobalColor c)
 Fills the given rectangle with the specified color. More...
 
void fillRect (int x, int y, int w, int h, Qt::BrushStyle style)
 Fills the rectangle beginning at ({x}, {y}) with the given width and height, using the brush style specified. More...
 
void fillRect (const QRect &r, Qt::BrushStyle style)
 Fills the given rectangle with the brush style specified. More...
 
void fillRect (const QRectF &r, Qt::BrushStyle style)
 Fills the given rectangle with the brush style specified. More...
 
const QFontfont () const
 Returns the currently set font used for drawing text. More...
 
QFontInfo fontInfo () const
 Returns the font info for the painter if the painter is active. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the painter if the painter is active. More...
 
bool hasClipping () const
 Returns true if clipping has been set; otherwise returns false. More...
 
void initFrom (const QWidget *widget)
 Initializes the painters pen, background and font to the same as the given widget. More...
 
bool isActive () const
 Returns true if begin() has been called and end() has not yet been called; otherwise returns false. More...
 
Qt::LayoutDirection layoutDirection () const
 Returns the layout direction used by the painter when drawing text. More...
 
const QMatrixmatrix () const
 Use worldTransform() instead. More...
 
bool matrixEnabled () const
 
qreal opacity () const
 Returns the opacity of the painter. More...
 
QPaintEnginepaintEngine () const
 Returns the paint engine that the painter is currently operating on if the painter is active; otherwise 0. More...
 
const QPenpen () const
 Returns the painter's current pen. More...
 
 QPainter ()
 Constructs a painter. More...
 
 QPainter (QPaintDevice *)
 Constructs a painter that begins painting the paint device immediately. More...
 
RenderHints renderHints () const
 Returns a flag that specifies the rendering hints that are set for this painter. More...
 
void resetMatrix ()
 Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldMatrix(), setViewport() and setWindow(). More...
 
void resetTransform ()
 Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldTransform(), setViewport() and setWindow(). More...
 
void restore ()
 Restores the current painter state (pops a saved state off the stack). More...
 
void rotate (qreal a)
 Rotates the coordinate system the given angle clockwise. More...
 
void save ()
 Saves the current painter state (pushes the state onto a stack). More...
 
void scale (qreal sx, qreal sy)
 Scales the coordinate system by ({sx}, {sy}). More...
 
void setBackground (const QBrush &bg)
 Sets the background brush of the painter to the given brush. More...
 
void setBackgroundMode (Qt::BGMode mode)
 Sets the background mode of the painter to the given mode. More...
 
void setBrush (const QBrush &brush)
 Sets the painter's brush to the given brush. More...
 
void setBrush (Qt::BrushStyle style)
 Sets the painter's brush to black color and the specified style. More...
 
void setBrushOrigin (int x, int y)
 Sets the brush's origin to point (x, y). More...
 
void setBrushOrigin (const QPoint &)
 Sets the brush's origin to the given position. More...
 
void setBrushOrigin (const QPointF &)
 Sets the brush origin to position. More...
 
void setClipPath (const QPainterPath &path, Qt::ClipOperation op=Qt::ReplaceClip)
 Enables clipping, and sets the clip path for the painter to the given path, with the clip operation. More...
 
void setClipping (bool enable)
 Enables clipping if enable is true, or disables clipping if enable is false. More...
 
void setClipRect (const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
 Enables clipping, and sets the clip region to the given rectangle using the given clip operation. More...
 
void setClipRect (const QRect &, Qt::ClipOperation op=Qt::ReplaceClip)
 Enables clipping, and sets the clip region to the given rectangle using the given clip operation. More...
 
void setClipRect (int x, int y, int w, int h, Qt::ClipOperation op=Qt::ReplaceClip)
 Enables clipping, and sets the clip region to the rectangle beginning at (x, y) with the given width and height. More...
 
void setClipRegion (const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
 Sets the clip region to the given region using the specified clip operation. More...
 
void setCompositionMode (CompositionMode mode)
 Sets the composition mode to the given mode. More...
 
void setFont (const QFont &f)
 Sets the painter's font to the given font. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 Sets the layout direction used by the painter when drawing text, to the specified direction. More...
 
void setMatrix (const QMatrix &matrix, bool combine=false)
 Use setWorldTransform() instead. More...
 
void setMatrixEnabled (bool enabled)
 Use setWorldMatrixEnabled() instead. More...
 
void setOpacity (qreal opacity)
 Sets the opacity of the painter to opacity. More...
 
void setPen (const QColor &color)
 Sets the painter's pen to have style Qt::SolidLine, width 0 and the specified color. More...
 
void setPen (const QPen &pen)
 Sets the painter's pen to be the given pen. More...
 
void setPen (Qt::PenStyle style)
 Sets the painter's pen to have the given style, width 0 and black color. More...
 
void setRenderHint (RenderHint hint, bool on=true)
 Sets the given render hint on the painter if on is true; otherwise clears the render hint. More...
 
void setRenderHints (RenderHints hints, bool on=true)
 Sets the given render hints on the painter if on is true; otherwise clears the render hints. More...
 
void setTransform (const QTransform &transform, bool combine=false)
 Sets the world transformation matrix. More...
 
void setViewport (const QRect &viewport)
 Sets the painter's viewport rectangle to the given rectangle, and enables view transformations. More...
 
void setViewport (int x, int y, int w, int h)
 Sets the painter's viewport rectangle to be the rectangle beginning at (x, y) with the given width and height. More...
 
void setViewTransformEnabled (bool enable)
 Enables view transformations if enable is true, or disables view transformations if enable is false. More...
 
void setWindow (const QRect &window)
 Sets the painter's window to the given rectangle, and enables view transformations. More...
 
void setWindow (int x, int y, int w, int h)
 Sets the painter's window to the rectangle beginning at (x, y) and the given width and height. More...
 
void setWorldMatrix (const QMatrix &matrix, bool combine=false)
 Sets the transformation matrix to matrix and enables transformations. More...
 
void setWorldMatrixEnabled (bool enabled)
 Enables transformations if enable is true, or disables transformations if enable is false. More...
 
void setWorldTransform (const QTransform &matrix, bool combine=false)
 Sets the world transformation matrix. More...
 
void shear (qreal sh, qreal sv)
 Shears the coordinate system by ({sh}, {sv}). More...
 
void strokePath (const QPainterPath &path, const QPen &pen)
 Draws the outline (strokes) the path path with the pen specified by pen. More...
 
bool testRenderHint (RenderHint hint) const
 Returns true if hint is set; otherwise returns false. More...
 
const QTransformtransform () const
 Returns the world transformation matrix. More...
 
void translate (const QPointF &offset)
 Translates the coordinate system by the given offset; i.e. More...
 
void translate (const QPoint &offset)
 Translates the coordinate system by the given offset. More...
 
void translate (qreal dx, qreal dy)
 Translates the coordinate system by the vector (dx, dy). More...
 
QRect viewport () const
 Returns the viewport rectangle. More...
 
bool viewTransformEnabled () const
 Returns true if view transformation is enabled; otherwise returns false. More...
 
QRect window () const
 Returns the window rectangle. More...
 
const QMatrixworldMatrix () const
 Returns the world transformation matrix. More...
 
bool worldMatrixEnabled () const
 Returns true if world transformation is enabled; otherwise returns false. More...
 
const QTransformworldTransform () const
 Returns the world transformation matrix. More...
 
 ~QPainter ()
 Destroys the painter. More...
 

Static Public Functions

static QPaintDeviceredirected (const QPaintDevice *device, QPoint *offset=0)
 Using QWidget::render() obsoletes the use of this function. More...
 
static void restoreRedirected (const QPaintDevice *device)
 Using QWidget::render() obsoletes the use of this function. More...
 
static void setRedirected (const QPaintDevice *device, QPaintDevice *replacement, const QPoint &offset=QPoint())
 Please use QWidget::render() instead. More...
 

Properties

QScopedPointer< QPainterPrivated_ptr
 

Friends

class Q3Painter
 
class QAlphaPaintEngine
 
class QFontEngine
 
class QFontEngineBox
 
class QFontEngineFT
 
class QFontEngineMac
 
class QFontEngineWin
 
class QFontEngineXLFD
 
class QOpenGLPaintEngine
 
class QPaintEngine
 
class QPaintEngineExPrivate
 
class QPreviewPaintEngine
 
class QRasterPaintEngine
 
class QVGPaintEngine
 
class QWin32PaintEngine
 
class QWin32PaintEnginePrivate
 
class QWSManager
 
class QX11PaintEngine
 
class QX11PaintEnginePrivate
 

Detailed Description

The QPainter class performs low-level painting on widgets and other paint devices.

Note
This class or function is reentrant.

QPainter provides highly optimized functions to do most of the drawing GUI programs require. It 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 "natural" coordinate system, but it can also do view and world transformation. QPainter can operate on any object that inherits the QPaintDevice class.

The common use of QPainter is inside a widget's paint event: Construct and customize (e.g. set the pen or the brush) the painter. Then draw. Remember to destroy the QPainter object after drawing. For example:

void SimpleExampleWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::blue);
painter.setFont(QFont("Arial", 30));
painter.drawText(rect(), Qt::AlignCenter, "Qt");
}

The core functionality of QPainter is drawing, but the class also provide several functions that allows you to customize QPainter's settings and its rendering quality, and others that enable clipping. In addition you can control how different shapes are merged together by specifying the painter's composition mode.

The isActive() function indicates whether the painter is active. A painter is activated by the begin() function and the constructor that takes a QPaintDevice argument. The end() function, and the destructor, deactivates it.

Together with the QPaintDevice and QPaintEngine classes, QPainter form the basis for Qt's paint system. QPainter is the class used to perform drawing operations. QPaintDevice represents a device that can be painted on using a QPainter. QPaintEngine provides the interface that the painter uses to draw onto different types of devices. If the painter is active, device() 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, see the Paint System.

Sometimes it is desirable to make someone else paint on an unusual QPaintDevice. QPainter supports a static function to do this, setRedirected().

Warning
When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting.

Settings

There are several settings that you can customize to make QPainter draw according to your preferences:

Note that some of these settings mirror settings in some paint devices, e.g. QWidget::font(). The QPainter::begin() function (or equivalently the QPainter constructor) copies these attributes from the paint device.

You can at any time save the QPainter's state by calling the save() function which saves all the available settings on an internal stack. The restore() function pops them back.

Drawing

QPainter provides functions to draw most primitives: drawPoint(), drawPoints(), drawLine(), drawRect(), drawRoundedRect(), drawEllipse(), drawArc(), drawPie(), drawChord(), drawPolyline(), drawPolygon(), drawConvexPolygon() and drawCubicBezier(). The two convenience functions, drawRects() and drawLines(), draw the given number of rectangles or lines in the given array of QRects or QLine using the current pen and brush.

The QPainter class also provides the fillRect() function which fills the given QRect, with the given QBrush, and the eraseRect() function that erases the area inside the given rectangle.

All of these functions have both integer and floating point versions.

qpainter-basicdrawing.png

Basic Drawing Example

The painting/basicdrawing{Basic Drawing} example shows how to display basic graphics primitives in a variety of styles using the QPainter class.

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().

Painter Paths example

The QPainterPath class provides a container for painting operations, enabling graphical shapes to be constructed and reused.

The painting/painterpaths{Painter Paths} example shows how painter paths can be used to build complex shapes for rendering.

qpainter-painterpaths.png

QPainter also provides the fillPath() function which fills the given QPainterPath with the given QBrush, and the strokePath() function that draws the outline of the given path (i.e. strokes the path).

See also the demos/deform{Vector Deformation} demo which shows how to use advanced vector techniques to draw text using a QPainterPath, the demos/gradients{Gradients} demo which shows the different types of gradients that are available in Qt, and the Path Stroking demo which shows Qt's built-in dash patterns and shows how custom patterns can be used to extend the range of available patterns.

demos/deform{Vector Deformation} demos/gradients{Gradients} demos/pathstroke{Path Stroking}
qpainter-vectordeformation.png
qpainter-gradients.png
qpainter-pathstroking.png

There are functions 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 is a drawPicture() function that draws the contents of an entire QPicture. The drawPicture() function is the only function that disregards all the painter's settings as QPicture has its own settings.

Rendering Quality

To get the optimal rendering result using QPainter, you should use the platform independent QImage as paint device; i.e. 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 functions for drawing primitives has a floating point version. These are often used in combination with the RenderHint{QPainter::Antialiasing} render hint.

qpainter-concentriccircles.png

Concentric Circles Example

The painting/concentriccircles{Concentric Circles} example shows the improved rendering quality that can be obtained using floating point precision and anti-aliasing when drawing custom widgets.

The application's main window displays several widgets which are drawn using the various combinations of precision and anti-aliasing.

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. RenderHint {HighQualityAntialiasing} is an OpenGL-specific rendering hint indicating that the engine should use fragment programs and offscreen rendering for antialiasing.

The renderHints() function returns a flag that specifies the rendering hints that are set for this painter. Use the setRenderHint() function to set or clear the currently set RenderHints.

Coordinate Transformations

Normally, the QPainter operates on the device's own coordinate system (usually pixels), but QPainter has good support for coordinate transformations.

nop rotate() scale() translate()
qpainter-clock.png
qpainter-rotation.png
qpainter-scale.png
qpainter-translation.png

The most commonly used transformations are scaling, rotation, translation and shearing. Use the scale() function to scale the coordinate system by a given offset, the rotate() function to rotate it clockwise and translate() to translate it (i.e. adding a given offset to the points). You can also twist the coordinate system around the origin using the shear() function. See the Affine Transformations demo for a visualization of a sheared coordinate system.

See also the painting/transformations{Transformations} example which shows how transformations influence the way that QPainter renders graphics primitives. In particular it shows how the order of transformations affects the result.

Affine Transformations Demo

The demos/affine{Affine Transformations} demo show Qt's ability to perform affine transformations on painting operations. The demo also allows the user to experiment with the transformation operations and see the results immediately.

qpainter-affinetransformations.png

All the tranformation operations operate on the transformation worldTransform(). A matrix transforms a point in the plane to another point. For more information about the transformation matrix, see the Coordinate System and QTransform documentation.

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 nativly.

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.

See also Coordinate System

Clipping

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 QPainter's 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().

Composition Modes

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 QPainter::CompositionMode and QPainter::CompositionMode . QPainter::CompositionMode 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 QPainter::CompositionMode composition mode, the source object is transparent and is drawn on top of the destination.

Note that composition transformation operates pixelwise. For that reason, there is a difference between using the graphic primitive itself and its bounding rectangle: The bounding rect contains pixels with alpha == 0 (i.e the pixels surrounding the primitive). These pixels will overwrite the other image's pixels, affectively clearing those, while the primitive only overwrites its own area.

qpainter-compositiondemo.png

Composition Modes Demo

The demos/composition{Composition Modes} demo, available in Qt's demo directory, allows you to experiment with the various composition modes and see the results immediately.

Limitations

If you are using coordinates with Qt's raster-based paint engine, it is important to note that, while coordinates greater than +/- 2 15 can be used, any painting performed with coordinates outside this range is not guaranteed to be shown; the drawing may be clipped. This is due to the use of short int in the implementation.

The outlines generated by Qt's stroker are only an approximation when dealing with curved shapes. It is in most cases impossible to represent the outline of a bezier curve segment using another bezier curve segment, and so Qt approximates the curve outlines by using several smaller curves. For performance reasons there is a limit to how many curves Qt uses for these outlines, and thus when using large pen widths or scales the outline error increases. To generate outlines with smaller errors it is possible to use the QPainterPathStroker class, which has the setCurveThreshold member function which let's the user specify the error tolerance. Another workaround is to convert the paths to polygons first and then draw the polygons instead.

Performance

QPainter is a rich framework that allows developers to do a great variety of graphical operations, such as gradients, composition modes and vector graphics. And QPainter can do this across a variety of different hardware and software stacks. Naturally the underlying combination of hardware and software has some implications for performance, and ensuring that every single operation is fast in combination with all the various combinations of composition modes, brushes, clipping, transformation, etc, is close to an impossible task because of the number of permutations. As a compromise we have selected a subset of the QPainter API and backends, where performance is guaranteed to be as good as we can sensibly get it for the given combination of hardware and software.

The backends we focus on as high-performance engines are:

These operations are:

This list gives an indication of which features to safely use in an application where performance is critical. For certain setups, other operations may be fast too, but before making extensive use of them, it is recommended to benchmark and verify them on the system where the software will run in the end. There are also cases where expensive operations are ok to use, for instance when the result is cached in a QPixmap.

See also
QPaintDevice, QPaintEngine, {QtSvg Module}, {Basic Drawing Example}, {Drawing Utility Functions}

Definition at line 86 of file qpainter.h.

Enumerations

◆ CompositionMode

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.

qpainter-compositionmode1.png
qpainter-compositionmode2.png

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 QImage::Format{Format_ARGB32Premultiplied} or QImage::Format{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.

  • CompositionMode_SourceOver This is the default mode. The alpha of the source is used to blend the pixel on top of the destination.
  • CompositionMode_DestinationOver The alpha of the destination is used to blend it on top of the source pixels. This mode is the inverse of CompositionMode_SourceOver.
  • CompositionMode_Clear The pixels in the destination are cleared (set to fully transparent) independent of the source.
  • CompositionMode_Source The output is the source pixel. (This means a basic copy operation and is identical to SourceOver when the source pixel is opaque).
  • CompositionMode_Destination The output is the destination pixel. This means that the blending has no effect. This mode is the inverse of CompositionMode_Source.
  • CompositionMode_SourceIn The output is the source, where the alpha is reduced by that of the destination.
  • CompositionMode_DestinationIn The output is the destination, where the alpha is reduced by that of the source. This mode is the inverse of CompositionMode_SourceIn.
  • CompositionMode_SourceOut The output is the source, where the alpha is reduced by the inverse of destination.
  • CompositionMode_DestinationOut The output is the destination, where the alpha is reduced by the inverse of the source. This mode is the inverse of CompositionMode_SourceOut.
  • CompositionMode_SourceAtop 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.
  • CompositionMode_DestinationAtop 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.
  • CompositionMode_Xor 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.
  • CompositionMode_Plus Both the alpha and color of the source and destination pixels are added together.
  • CompositionMode_Multiply 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.
  • CompositionMode_Screen 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.
  • CompositionMode_Overlay 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.
  • CompositionMode_Darken The darker of the source and destination colors is selected.
  • CompositionMode_Lighten The lighter of the source and destination colors is selected.
  • CompositionMode_ColorDodge The destination color is brightened to reflect the source color. A black source color leaves the destination color unchanged.
  • CompositionMode_ColorBurn The destination color is darkened to reflect the source color. A white source color leaves the destination color unchanged.
  • CompositionMode_HardLight 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.
  • CompositionMode_SoftLight Darkens or lightens the colors depending on the source color. Similar to CompositionMode_HardLight.
  • CompositionMode_Difference 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.
  • CompositionMode_Exclusion 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.
  • RasterOp_SourceOrDestination Does a bitwise OR operation on the source and destination pixels (src OR dst).
  • RasterOp_SourceAndDestination Does a bitwise AND operation on the source and destination pixels (src AND dst).
  • RasterOp_SourceXorDestination Does a bitwise XOR operation on the source and destination pixels (src XOR dst).
  • RasterOp_NotSourceAndNotDestination Does a bitwise NOR operation on the source and destination pixels ((NOT src) AND (NOT dst)).
  • RasterOp_NotSourceOrNotDestination Does a bitwise NAND operation on the source and destination pixels ((NOT src) OR (NOT dst)).
  • RasterOp_NotSourceXorDestination Does a bitwise operation where the source pixels are inverted and then XOR'ed with the destination ((NOT src) XOR dst).
  • RasterOp_NotSource Does a bitwise operation where the source pixels are inverted (NOT src).
  • RasterOp_NotSourceAndDestination Does a bitwise operation where the source is inverted and then AND'ed with the destination ((NOT src) AND dst).
  • RasterOp_SourceAndNotDestination Does a bitwise operation where the source is AND'ed with the inverted destination pixels (src AND (NOT dst)).
See also
compositionMode(), setCompositionMode(), {QPainter::Composition Modes}{Composition Modes}, {Image Composition Example}
Enumerator
CompositionMode_SourceOver 
CompositionMode_DestinationOver 
CompositionMode_Clear 
CompositionMode_Source 
CompositionMode_Destination 
CompositionMode_SourceIn 
CompositionMode_DestinationIn 
CompositionMode_SourceOut 
CompositionMode_DestinationOut 
CompositionMode_SourceAtop 
CompositionMode_DestinationAtop 
CompositionMode_Xor 
CompositionMode_Plus 
CompositionMode_Multiply 
CompositionMode_Screen 
CompositionMode_Overlay 
CompositionMode_Darken 
CompositionMode_Lighten 
CompositionMode_ColorDodge 
CompositionMode_ColorBurn 
CompositionMode_HardLight 
CompositionMode_SoftLight 
CompositionMode_Difference 
CompositionMode_Exclusion 
RasterOp_SourceOrDestination 
RasterOp_SourceAndDestination 
RasterOp_SourceXorDestination 
RasterOp_NotSourceAndNotDestination 
RasterOp_NotSourceOrNotDestination 
RasterOp_NotSourceXorDestination 
RasterOp_NotSource 
RasterOp_NotSourceAndDestination 
RasterOp_SourceAndNotDestination 

Definition at line 138 of file qpainter.h.

138  {
151 
152  //svg 1.2 blend modes
165 
166  // ROPs
176  };

◆ PixmapFragmentHint

Since
4.7
  • OpaqueHint Indicates that the pixmap fragments to be drawn are opaque. Opaque fragments are potentially faster to draw.
See also
QPainter::drawPixmapFragments(), QPainter::PixmapFragment
Enumerator
OpaqueHint 

Definition at line 120 of file qpainter.h.

120  {
121  OpaqueHint = 0x01
122  };

◆ RenderHint

Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine.

  • Antialiasing Indicates that the engine should antialias edges of primitives if possible.
  • TextAntialiasing 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.
  • SmoothPixmapTransform Indicates that the engine should use a smooth pixmap transformation algorithm (such as bilinear) rather than nearest neighbor.
  • HighQualityAntialiasing An OpenGL-specific rendering hint indicating that the engine should use fragment programs and offscreen rendering for antialiasing.
  • NonCosmeticDefaultPen 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.
See also
renderHints(), setRenderHint(), {QPainter::Rendering Quality}{Rendering Quality}, {Concentric Circles Example}
Enumerator
Antialiasing 
TextAntialiasing 
SmoothPixmapTransform 
HighQualityAntialiasing 
NonCosmeticDefaultPen 

Definition at line 93 of file qpainter.h.

Constructors and Destructors

◆ QPainter() [1/2]

QPainter::QPainter ( )

Constructs a painter.

See also
begin(), end()

Definition at line 1459 of file qpainter.cpp.

1460  : d_ptr(new QPainterPrivate(this))
1461 {
1462 }
QScopedPointer< QPainterPrivate > d_ptr
Definition: qpainter.h:546

◆ QPainter() [2/2]

QPainter::QPainter ( QPaintDevice device)
explicit

Constructs a painter that begins painting the paint device immediately.

This constructor is convenient for short-lived painters, e.g. in a QWidget::paintEvent() and should be used only once. The constructor calls begin() for you and the QPainter destructor automatically calls end().

Here's an example using begin() and end():

void MyWidget::paintEvent(QPaintEvent *)
{
p.begin(this);
p.drawLine(...); // drawing code
p.end();
}

The same example using this constructor:

void MyWidget::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.drawLine(...); // drawing code
}

Since the constructor cannot provide feedback when the initialization of the painter failed you should rather use begin() and end() to paint on external devices, e.g. printers.

See also
begin(), end()

Definition at line 1488 of file qpainter.cpp.

1489  : d_ptr(0)
1490 {
1491  Q_ASSERT(pd != 0);
1492  if (!QPainterPrivate::attachPainterPrivate(this, pd)) {
1493  d_ptr.reset(new QPainterPrivate(this));
1494  begin(pd);
1495  }
1496  Q_ASSERT(d_ptr);
1497 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool begin(QPaintDevice *)
Begins painting the paint device and returns true if successful; otherwise returns false...
Definition: qpainter.cpp:1723
static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev)
Definition: qpainter.cpp:240
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QScopedPointer< QPainterPrivate > d_ptr
Definition: qpainter.h:546

◆ ~QPainter()

QPainter::~QPainter ( )

Destroys the painter.

Definition at line 1502 of file qpainter.cpp.

1503 {
1504  d_ptr->inDestructor = true;
1505  QT_TRY {
1506  if (isActive())
1507  end();
1508  else if (d_ptr->refcount > 1)
1509  d_ptr->detachPainterPrivate(this);
1510  } QT_CATCH(...) {
1511  // don't throw anything in the destructor.
1512  }
1513  if (d_ptr) {
1514  // Make sure we haven't messed things up.
1516  d_ptr->inDestructor = false;
1517  Q_ASSERT(d_ptr->refcount == 1);
1518  if (d_ptr->d_ptrs)
1519  free(d_ptr->d_ptrs);
1520  }
1521 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
Definition: qpainter.cpp:1545
#define QT_CATCH(A)
Definition: qglobal.h:1537
void detachPainterPrivate(QPainter *q)
Definition: qpainter.cpp:328
QPainterPrivate ** d_ptrs
Definition: qpainter_p.h:202
#define QT_TRY
Definition: qglobal.h:1536
bool end()
Ends painting.
Definition: qpainter.cpp:1929
QScopedPointer< QPainterPrivate > d_ptr
Definition: qpainter.h:546

Functions

◆ background()

const QBrush & QPainter::background ( ) const

Returns the current background brush.

See also
setBackground(), {QPainter::Settings}{Settings}

Definition at line 2482 of file qpainter.cpp.

Referenced by QMotifStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QStyle::drawItemText(), QWindowsMobileStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), and QMotifStyle::drawPrimitive().

2483 {
2484  Q_D(const QPainter);
2485  if (!d->engine) {
2486  qWarning("QPainter::background: Painter not active");
2487  return d->fakeState()->brush;
2488  }
2489  return d->state->bgBrush;
2490 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ backgroundMode()

Qt::BGMode QPainter::backgroundMode ( ) const

Returns the current background mode.

See also
setBackgroundMode(), {QPainter::Settings}{Settings}

Definition at line 4026 of file qpainter.cpp.

Referenced by QWindowsCEStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), and QWindowsStyle::drawControl().

4027 {
4028  Q_D(const QPainter);
4029  if (!d->engine) {
4030  qWarning("QPainter::backgroundMode: Painter not active");
4031  return Qt::TransparentMode;
4032  }
4033  return d->state->bgMode;
4034 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ begin()

bool QPainter::begin ( QPaintDevice device)

Begins painting the paint device and returns true if successful; otherwise returns false.

Use begin() instead.

Notice that all painter settings (setPen(), setBrush() etc.) are reset to default values when begin() is called.

The errors that can occur are serious problems, such as these:

painter->begin(0); // impossible - paint device cannot be 0
QPixmap image(0, 0);
painter->begin(&image); // impossible - image.isNull() == true;
painter->begin(myWidget);
painter2->begin(myWidget); // impossible - only one painter at a time

Note that most of the time, you can use one of the constructors instead of begin(), and that end() is automatically done at destruction.

Warning
A paint device can only be painted by one painter at a time.
Painting on a QImage with the format QImage::Format_Indexed8 is not supported.
See also
end(), QPainter()

If the paint device is a QWidget, QPainter is initialized after the widget's settings automatically. Otherwise, you must call the initFrom() function to initialize the painters pen, background and font to the same as any given widget.

QPainter painter(this); painter.begin(device, init); QPainter painter(this); painter.begin(device); painter.initFrom(init);

Definition at line 1723 of file qpainter.cpp.

Referenced by _q_paintIntoCache(), QStylePainter::begin(), QWindowsStyle::drawComplexControl(), QPainter(), toVGImageWithOpacity(), and toVGImageWithOpacitySubRect().

1724 {
1725  Q_ASSERT(pd);
1726 
1727  if (pd->painters > 0) {
1728  qWarning("QPainter::begin: A paint device can only be painted by one painter at a time.");
1729  return false;
1730  }
1731 
1732  if (d_ptr->engine) {
1733  qWarning("QPainter::begin: Painter already active");
1734  return false;
1735  }
1736 
1738  return true;
1739 
1740  Q_D(QPainter);
1741 
1742  d->helper_device = pd;
1743  d->original_device = pd;
1744  QPaintDevice *rpd = 0;
1745 
1746  QPoint redirectionOffset;
1747  // We know for sure that redirection is broken when the widget is inside
1748  // its paint event, so it's safe to use our hard-coded redirection. However,
1749  // there IS one particular case we still need to support, and that's
1750  // when people call QPainter::setRedirected in the widget's paint event right
1751  // before any painter is created (or QPainter::begin is called). In that
1752  // particular case our hard-coded redirection is restored and the redirection
1753  // is retrieved from QPainter::redirected (as before).
1754  if (pd->devType() == QInternal::Widget)
1755  rpd = static_cast<QWidget *>(pd)->d_func()->redirected(&redirectionOffset);
1756 
1757  if (!rpd)
1758  rpd = redirected(pd, &redirectionOffset);
1759 
1760  if (rpd)
1761  pd = rpd;
1762 
1763 #ifdef QT_DEBUG_DRAW
1764  if (qt_show_painter_debug_output)
1765  printf("QPainter::begin(), device=%p, type=%d\n", pd, pd->devType());
1766 #endif
1767 
1768  if (pd->devType() == QInternal::Pixmap)
1769  static_cast<QPixmap *>(pd)->detach();
1770  else if (pd->devType() == QInternal::Image)
1771  static_cast<QImage *>(pd)->detach();
1772 
1773  d->engine = pd->paintEngine();
1774 
1775  if (!d->engine) {
1776  qWarning("QPainter::begin: Paint device returned engine == 0, type: %d", pd->devType());
1777  return false;
1778  }
1779 
1780  d->device = pd;
1781 
1782  d->extended = d->engine->isExtended() ? static_cast<QPaintEngineEx *>(d->engine) : 0;
1783  if (d->emulationEngine)
1784  d->emulationEngine->real_engine = d->extended;
1785 
1786  // Setup new state...
1787  Q_ASSERT(!d->state);
1788  d->state = d->extended ? d->extended->createState(0) : new QPainterState;
1789  d->state->painter = this;
1790  d->states.push_back(d->state);
1791 
1792  d->state->redirectionMatrix.translate(-redirectionOffset.x(), -redirectionOffset.y());
1793  d->state->brushOrigin = QPointF();
1794 
1795  // Slip a painter state into the engine before we do any other operations
1796  if (d->extended)
1797  d->extended->setState(d->state);
1798  else
1799  d->engine->state = d->state;
1800 
1801  switch (pd->devType()) {
1802  case QInternal::Widget:
1803  {
1804  const QWidget *widget = static_cast<const QWidget *>(pd);
1805  Q_ASSERT(widget);
1806 
1807  const bool paintOutsidePaintEvent = widget->testAttribute(Qt::WA_PaintOutsidePaintEvent);
1808  const bool inPaintEvent = widget->testAttribute(Qt::WA_WState_InPaintEvent);
1809  if(!d->engine->hasFeature(QPaintEngine::PaintOutsidePaintEvent)
1810  && !paintOutsidePaintEvent && !inPaintEvent) {
1811  qWarning("QPainter::begin: Widget painting can only begin as a "
1812  "result of a paintEvent");
1814  return false;
1815  }
1816 
1817  // Adjust offset for alien widgets painting outside the paint event.
1818  if (!inPaintEvent && paintOutsidePaintEvent && !widget->internalWinId()
1819  && widget->testAttribute(Qt::WA_WState_Created)) {
1820  const QPoint offset = widget->mapTo(widget->nativeParentWidget(), QPoint());
1821  d->state->redirectionMatrix.translate(offset.x(), offset.y());
1822  }
1823  break;
1824  }
1825  case QInternal::Pixmap:
1826  {
1827  QPixmap *pm = static_cast<QPixmap *>(pd);
1828  Q_ASSERT(pm);
1829  if (pm->isNull()) {
1830  qWarning("QPainter::begin: Cannot paint on a null pixmap");
1832  return false;
1833  }
1834 
1835  if (pm->depth() == 1) {
1836  d->state->pen = QPen(Qt::color1);
1837  d->state->brush = QBrush(Qt::color0);
1838  }
1839  break;
1840  }
1841  case QInternal::Image:
1842  {
1843  QImage *img = static_cast<QImage *>(pd);
1844  Q_ASSERT(img);
1845  if (img->isNull()) {
1846  qWarning("QPainter::begin: Cannot paint on a null image");
1848  return false;
1849  } else if (img->format() == QImage::Format_Indexed8) {
1850  // Painting on indexed8 images is not supported.
1851  qWarning("QPainter::begin: Cannot paint on an image with the QImage::Format_Indexed8 format");
1853  return false;
1854  }
1855  if (img->depth() == 1) {
1856  d->state->pen = QPen(Qt::color1);
1857  d->state->brush = QBrush(Qt::color0);
1858  }
1859  break;
1860  }
1861  default:
1862  break;
1863  }
1864  if (d->state->ww == 0) // For compat with 3.x painter defaults
1865  d->state->ww = d->state->wh = d->state->vw = d->state->vh = 1024;
1866 
1867  d->engine->setPaintDevice(pd);
1868 
1869  bool begun = d->engine->begin(pd);
1870  if (!begun) {
1871  qWarning("QPainter::begin(): Returned false");
1872  if (d->engine->isActive()) {
1873  end();
1874  } else {
1876  }
1877  return false;
1878  } else {
1879  d->engine->setActive(begun);
1880  }
1881 
1882  // Copy painter properties from original paint device,
1883  // required for QPixmap::grabWidget()
1884  if (d->original_device->devType() == QInternal::Widget) {
1885  QWidget *widget = static_cast<QWidget *>(d->original_device);
1886  initFrom(widget);
1887  } else {
1888  d->state->layoutDirection = Qt::LayoutDirectionAuto;
1889  // make sure we have a font compatible with the paintdevice
1890  d->state->deviceFont = d->state->font = QFont(d->state->deviceFont, device());
1891  }
1892 
1893  QRect systemRect = d->engine->systemRect();
1894  if (!systemRect.isEmpty()) {
1895  d->state->ww = d->state->vw = systemRect.width();
1896  d->state->wh = d->state->vh = systemRect.height();
1897  } else {
1898  d->state->ww = d->state->vw = pd->metric(QPaintDevice::PdmWidth);
1899  d->state->wh = d->state->vh = pd->metric(QPaintDevice::PdmHeight);
1900  }
1901 
1902  const QPoint coordinateOffset = d->engine->coordinateOffset();
1903  d->state->redirectionMatrix.translate(-coordinateOffset.x(), -coordinateOffset.y());
1904 
1905  Q_ASSERT(d->engine->isActive());
1906 
1907  if (!d->state->redirectionMatrix.isIdentity())
1908  d->updateMatrix();
1909 
1910  Q_ASSERT(d->engine->isActive());
1911  d->state->renderHints = QPainter::TextAntialiasing;
1912  ++d->device->painters;
1913 
1914  d->state->emulationSpecifier = 0;
1915 
1916  return true;
1917 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QPointer< QWidget > widget
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
static void qt_cleanup_painter_state(QPainterPrivate *d)
Definition: qpainter.cpp:1714
QWidget * nativeParentWidget() const
Returns the native parent for this widget, i.
Definition: qwidget.cpp:4514
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev)
Definition: qpainter.cpp:240
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
WId internalWinId() const
Returns the window system identifier of the widget, or 0 if the widget is not created yet...
Definition: qwidget.h:244
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void initFrom(const QWidget *widget)
Initializes the painters pen, background and font to the same as the given widget.
Definition: qpainter.cpp:1558
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
static QPaintDevice * redirected(const QPaintDevice *device, QPoint *offset=0)
Using QWidget::render() obsoletes the use of this function.
Definition: qpainter.cpp:8391
bool end()
Ends painting.
Definition: qpainter.cpp:1929
QScopedPointer< QPainterPrivate > d_ptr
Definition: qpainter.h:546
QPaintEngine * engine
Definition: qpainter_p.h:261

◆ beginNativePainting()

void QPainter::beginNativePainting ( )

Flushes the painting pipeline and prepares for the user issuing commands directly to the underlying graphics context.

Since
4.6

Must be followed by a call to endNativePainting().

Note that only the states the underlying paint engine changes will be reset to their respective default states. The states we reset may change from release to release. The following states are currently reset in the OpenGL 2 engine:

  • blending is disabled
  • the depth, stencil and scissor tests are disabled
  • the active texture unit is reset to 0
  • the depth mask, depth function and the clear depth are reset to their default values
  • the stencil mask, stencil operation and stencil function are reset to their default values
  • the current color is reset to solid white

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:

QPainter painter(this);
painter.fillRect(0, 0, 128, 128, Qt::green);
painter.beginNativePainting();
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, 64, 64);
glClearColor(1, 0, 0, 1);
glDisable(GL_SCISSOR_TEST);
painter.endNativePainting();
See also
endNativePainting()

Definition at line 2032 of file qpainter.cpp.

Referenced by ShaderEffectItem::paint().

2033 {
2034  Q_D(QPainter);
2035  if (!d->engine) {
2036  qWarning("QPainter::beginNativePainting: Painter not active");
2037  return;
2038  }
2039 
2040  if (d->extended)
2041  d->extended->beginNativePainting();
2042 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ boundingRect() [1/4]

QRectF QPainter::boundingRect ( const QRectF rectangle,
int  flags,
const QString text 
)

Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle with the specified flags using the currently set font(); i.

e the function tells you where the drawText() function will draw when given the same arguments.

If the text does not fit within the given rectangle using the specified flags, the function 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.

See also
drawText(), Qt::Alignment, Qt::TextFlag

Definition at line 7093 of file qpainter.cpp.

Referenced by qDrawPlainRect().

7094 {
7095  if (str.isEmpty())
7096  return QRectF(rect.x(),rect.y(), 0,0);
7097  QRectF brect;
7098  drawText(rect, flags | Qt::TextDontPrint, str, &brect);
7099  return brect;
7100 }
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ boundingRect() [2/4]

QRect QPainter::boundingRect ( const QRect rectangle,
int  flags,
const QString text 
)

Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle with the specified flags using the currently set font().

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 7082 of file qpainter.cpp.

7083 {
7084  if (str.isEmpty())
7085  return QRect(rect.x(),rect.y(), 0,0);
7086  QRect brect;
7087  drawText(rect, flags | Qt::TextDontPrint, str, &brect);
7088  return brect;
7089 }
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ boundingRect() [3/4]

QRect QPainter::boundingRect ( int  x,
int  y,
int  w,
int  h,
int  flags,
const QString text 
)
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 w and height h.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 970 of file qpainter.h.

971 {
972  return boundingRect(QRect(x, y, w, h), flags, text);
973 }
QRectF boundingRect(const QRectF &rect, int flags, const QString &text)
Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle wi...
Definition: qpainter.cpp:7093
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ boundingRect() [4/4]

QRectF QPainter::boundingRect ( const QRectF rectangle,
const QString text,
const QTextOption option = QTextOption() 
)

Instead of specifying flags as a bitwise OR of the Qt::AlignmentFlag and Qt::TextFlag, this overloaded function takes an option argument.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The QTextOption class provides a description of general rich text properties.

See also
QTextOption

Definition at line 7118 of file qpainter.cpp.

7119 {
7120  Q_D(QPainter);
7121 
7122  if (!d->engine || text.length() == 0)
7123  return QRectF(r.x(),r.y(), 0,0);
7124 
7125  QRectF br;
7126  qt_format_text(d->state->font, r, Qt::TextDontPrint, &o, text, &br, 0, 0, 0, this);
7127  return br;
7128 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *option, const QString &str, QRectF *brect, int tabstops, int *tabarray, int tabarraylen, QPainter *painter)
Definition: qpainter.cpp:8458
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ brush()

const QBrush & QPainter::brush ( ) const

◆ brushOrigin()

QPoint QPainter::brushOrigin ( ) const

Returns the currently set brush origin.

See also
setBrushOrigin(), {QPainter::Settings}{Settings}

Definition at line 2168 of file qpainter.cpp.

Referenced by QItemDelegate::drawBackground(), QTreeView::drawBranches(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QCommonStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QTextDocumentLayoutPrivate::drawTableCell(), QCoreGraphicsPaintEngine::drawTextItem(), drawTextItemDecoration(), QWidgetPrivate::paintBackground(), QHeaderView::paintSection(), and qDrawPlainRect().

2169 {
2170  Q_D(const QPainter);
2171  if (!d->engine) {
2172  qWarning("QPainter::brushOrigin: Painter not active");
2173  return QPoint();
2174  }
2175  return QPointF(d->state->brushOrigin).toPoint();
2176 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ clipBoundingRect()

QRectF QPainter::clipBoundingRect ( ) const

Returns the bounding rectangle of the current clip if there is a clip; otherwise returns an empty rectangle.

Note that the clip region is given in logical coordinates.

The bounding rectangle is not guaranteed to be tight.

See also
setClipRect(), setClipPath(), setClipRegion()
Since
4.8

Definition at line 2741 of file qpainter.cpp.

2742 {
2743  Q_D(const QPainter);
2744 
2745  if (!d->engine) {
2746  qWarning("QPainter::clipBoundingRect: Painter not active");
2747  return QRectF();
2748  }
2749 
2750  // Accumulate the bounding box in device space. This is not 100%
2751  // precise, but it fits within the guarantee and it is reasonably
2752  // fast.
2753  QRectF bounds;
2754  for (int i=0; i<d->state->clipInfo.size(); ++i) {
2755  QRectF r;
2756  const QPainterClipInfo &info = d->state->clipInfo.at(i);
2757 
2759  r = info.rect;
2760  else if (info.clipType == QPainterClipInfo::RectFClip)
2761  r = info.rectf;
2762  else if (info.clipType == QPainterClipInfo::RegionClip)
2763  r = info.region.boundingRect();
2764  else
2765  r = info.path.boundingRect();
2766 
2767  r = info.matrix.mapRect(r);
2768 
2769  if (i == 0)
2770  bounds = r;
2771  else if (info.operation == Qt::IntersectClip)
2772  bounds &= r;
2773  else if (info.operation == Qt::UniteClip)
2774  bounds |= r;
2775  }
2776 
2777 
2778  // Map the rectangle back into logical space using the inverse
2779  // matrix.
2780  if (!d->txinv)
2781  const_cast<QPainter *>(this)->d_ptr->updateInvMatrix();
2782 
2783  return d->invMatrix.mapRect(bounds);
2784 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
static mach_timebase_info_data_t info
Qt::ClipOperation operation
Definition: qpainter_p.h:119
ClipType clipType
Definition: qpainter_p.h:117
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
#define Q_D(Class)
Definition: qglobal.h:2482
QRectF boundingRect() const
Returns the bounding rectangle of this painter path as a rectangle with floating point precision...
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPainterPath path
Definition: qpainter_p.h:120
Q_CORE_EXPORT void qWarning(const char *,...)
void updateInvMatrix()
Definition: qpainter.cpp:680
QTransform matrix
Definition: qpainter_p.h:118
QScopedPointer< QPainterPrivate > d_ptr
Definition: qpainter.h:546

◆ clipPath()

QPainterPath QPainter::clipPath ( ) const

Returns the currently clip as a path.

Note that the clip path is given in logical coordinates.

Warning
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.
See also
setClipPath(), clipRegion(), setClipping()

Definition at line 2690 of file qpainter.cpp.

Referenced by QX11PaintEnginePrivate::systemStateChanged(), QPdfBaseEngine::updateClipPath(), QWin32PrintEngine::updateState(), and QCoreGraphicsPaintEngine::updateState().

2691 {
2692  Q_D(const QPainter);
2693 
2694  // ### Since we do not support path intersections and path unions yet,
2695  // we just use clipRegion() here...
2696  if (!d->engine) {
2697  qWarning("QPainter::clipPath: Painter not active");
2698  return QPainterPath();
2699  }
2700 
2701  // No clip, return empty
2702  if (d->state->clipInfo.size() == 0) {
2703  return QPainterPath();
2704  } else {
2705 
2706  // Update inverse matrix, used below.
2707  if (!d->txinv)
2708  const_cast<QPainter *>(this)->d_ptr->updateInvMatrix();
2709 
2710  // For the simple case avoid conversion.
2711  if (d->state->clipInfo.size() == 1
2712  && d->state->clipInfo.at(0).clipType == QPainterClipInfo::PathClip) {
2713  QTransform matrix = (d->state->clipInfo.at(0).matrix * d->invMatrix);
2714  return d->state->clipInfo.at(0).path * matrix;
2715 
2716  } else if (d->state->clipInfo.size() == 1
2717  && d->state->clipInfo.at(0).clipType == QPainterClipInfo::RectClip) {
2718  QTransform matrix = (d->state->clipInfo.at(0).matrix * d->invMatrix);
2719  QPainterPath path;
2720  path.addRect(d->state->clipInfo.at(0).rect);
2721  return path * matrix;
2722  } else {
2723  // Fallback to clipRegion() for now, since we don't have isect/unite for paths
2724  return qt_regionToPath(clipRegion());
2725  }
2726  }
2727 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
QRegion clipRegion() const
Returns the currently set clip region.
Definition: qpainter.cpp:2562
const QMatrix & matrix() const
Use worldTransform() instead.
Definition: qpainter.cpp:3061
Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath(const QRegion &region)
Definition: qregion.cpp:1160
Q_CORE_EXPORT void qWarning(const char *,...)
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
void updateInvMatrix()
Definition: qpainter.cpp:680
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QScopedPointer< QPainterPrivate > d_ptr
Definition: qpainter.h:546

◆ clipRegion()

QRegion QPainter::clipRegion ( ) const

Returns the currently set clip region.

Note that the clip region is given in logical coordinates.

Warning
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.
See also
setClipRegion(), clipPath(), setClipping()

Definition at line 2562 of file qpainter.cpp.

Referenced by clipPath(), QWindowsXPStylePrivate::drawBackgroundDirectly(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QMacStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsMobileStyle::drawControl(), QDecorationStyled::paint(), QDecorationWindows::paint(), QDecorationDefault::paint(), QDeclarativePaintedItem::paint(), QMacCGContext::QMacCGContext(), QWidget::render(), QOpenGLPaintEngine::updateState(), and QPicturePaintEngine::writeCmdLength().

2563 {
2564  Q_D(const QPainter);
2565  if (!d->engine) {
2566  qWarning("QPainter::clipRegion: Painter not active");
2567  return QRegion();
2568  }
2569 
2570  QRegion region;
2571  bool lastWasNothing = true;
2572 
2573  if (!d->txinv)
2574  const_cast<QPainter *>(this)->d_ptr->updateInvMatrix();
2575 
2576  // ### Falcon: Use QPainterPath
2577  for (int i=0; i<d->state->clipInfo.size(); ++i) {
2578  const QPainterClipInfo &info = d->state->clipInfo.at(i);
2579  switch (info.clipType) {
2580 
2582  QTransform matrix = (info.matrix * d->invMatrix);
2583  if (lastWasNothing) {
2584  region = info.region * matrix;
2585  lastWasNothing = false;
2586  continue;
2587  }
2588  if (info.operation == Qt::IntersectClip)
2589  region &= info.region * matrix;
2590  else if (info.operation == Qt::UniteClip)
2591  region |= info.region * matrix;
2592  else if (info.operation == Qt::NoClip) {
2593  lastWasNothing = true;
2594  region = QRegion();
2595  } else
2596  region = info.region * matrix;
2597  break;
2598  }
2599 
2601  QTransform matrix = (info.matrix * d->invMatrix);
2602  if (lastWasNothing) {
2603  region = QRegion((info.path * matrix).toFillPolygon().toPolygon(),
2604  info.path.fillRule());
2605  lastWasNothing = false;
2606  continue;
2607  }
2608  if (info.operation == Qt::IntersectClip) {
2609  region &= QRegion((info.path * matrix).toFillPolygon().toPolygon(),
2610  info.path.fillRule());
2611  } else if (info.operation == Qt::UniteClip) {
2612  region |= QRegion((info.path * matrix).toFillPolygon().toPolygon(),
2613  info.path.fillRule());
2614  } else if (info.operation == Qt::NoClip) {
2615  lastWasNothing = true;
2616  region = QRegion();
2617  } else {
2618  region = QRegion((info.path * matrix).toFillPolygon().toPolygon(),
2619  info.path.fillRule());
2620  }
2621  break;
2622  }
2623 
2625  QTransform matrix = (info.matrix * d->invMatrix);
2626  if (lastWasNothing) {
2627  region = QRegion(info.rect) * matrix;
2628  lastWasNothing = false;
2629  continue;
2630  }
2631  if (info.operation == Qt::IntersectClip) {
2632  // Use rect intersection if possible.
2633  if (matrix.type() <= QTransform::TxScale)
2634  region &= matrix.mapRect(info.rect);
2635  else
2636  region &= matrix.map(QRegion(info.rect));
2637  } else if (info.operation == Qt::UniteClip) {
2638  region |= QRegion(info.rect) * matrix;
2639  } else if (info.operation == Qt::NoClip) {
2640  lastWasNothing = true;
2641  region = QRegion();
2642  } else {
2643  region = QRegion(info.rect) * matrix;
2644  }
2645  break;
2646  }
2647 
2649  QTransform matrix = (info.matrix * d->invMatrix);
2650  if (lastWasNothing) {
2651  region = QRegion(info.rectf.toRect()) * matrix;
2652  lastWasNothing = false;
2653  continue;
2654  }
2655  if (info.operation == Qt::IntersectClip) {
2656  // Use rect intersection if possible.
2657  if (matrix.type() <= QTransform::TxScale)
2658  region &= matrix.mapRect(info.rectf.toRect());
2659  else
2660  region &= matrix.map(QRegion(info.rectf.toRect()));
2661  } else if (info.operation == Qt::UniteClip) {
2662  region |= QRegion(info.rectf.toRect()) * matrix;
2663  } else if (info.operation == Qt::NoClip) {
2664  lastWasNothing = true;
2665  region = QRegion();
2666  } else {
2667  region = QRegion(info.rectf.toRect()) * matrix;
2668  }
2669  break;
2670  }
2671  }
2672  }
2673 
2674  return region;
2675 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
static mach_timebase_info_data_t info
Qt::ClipOperation operation
Definition: qpainter_p.h:119
ClipType clipType
Definition: qpainter_p.h:117
TransformationType type() const
Returns the transformation type of this matrix.
#define Q_D(Class)
Definition: qglobal.h:2482
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
const QMatrix & matrix() const
Use worldTransform() instead.
Definition: qpainter.cpp:3061
QPainterPath path
Definition: qpainter_p.h:120
Q_CORE_EXPORT void qWarning(const char *,...)
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
Qt::FillRule fillRule() const
Returns the painter path&#39;s currently set fill rule.
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
void updateInvMatrix()
Definition: qpainter.cpp:680
QTransform matrix
Definition: qpainter_p.h:118
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QScopedPointer< QPainterPrivate > d_ptr
Definition: qpainter.h:546

◆ combinedMatrix()

QMatrix QPainter::combinedMatrix ( ) const

Returns the transformation matrix combining the current window/viewport and world transformation.

Since
4.2

It is advisable to use combinedTransform() instead of this function to preserve the properties of perspective transformations.

See also
setWorldTransform(), setWindow(), setViewport()

Definition at line 3082 of file qpainter.cpp.

Referenced by setViewTransformEnabled().

3083 {
3084  return combinedTransform().toAffine();
3085 }
const QMatrix & toAffine() const
Returns the QTransform as an affine matrix.
QTransform combinedTransform() const
Returns the transformation matrix combining the current window/viewport and world transformation...
Definition: qpainter.cpp:9669

◆ combinedTransform()

QTransform QPainter::combinedTransform ( ) const

Returns the transformation matrix combining the current window/viewport and world transformation.

See also
setWorldTransform(), setWindow(), setViewport()

Definition at line 9669 of file qpainter.cpp.

Referenced by combinedMatrix(), QPixmapConvolutionFilter::draw(), qDrawBorderPixmap(), and QMacCGContext::QMacCGContext().

9670 {
9671  Q_D(const QPainter);
9672  if (!d->engine) {
9673  qWarning("QPainter::combinedTransform: Painter not active");
9674  return QTransform();
9675  }
9676  return d->state->worldMatrix * d->viewTransform();
9677 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ compositionMode()

QPainter::CompositionMode QPainter::compositionMode ( ) const

Returns the current composition mode.

See also
CompositionMode, setCompositionMode()

Definition at line 2466 of file qpainter.cpp.

Referenced by QSvgCompOpStyle::apply(), QDeclarativePaintedItem::paint(), and QWidgetPrivate::paintBackground().

2467 {
2468  Q_D(const QPainter);
2469  if (!d->engine) {
2470  qWarning("QPainter::compositionMode: Painter not active");
2472  }
2473  return d->state->composition_mode;
2474 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ device()

QPaintDevice * QPainter::device ( ) const

Returns the paint device on which this painter is currently painting, or 0 if the painter is not active.

See also
isActive()

Definition at line 1530 of file qpainter.cpp.

Referenced by begin(), QWindowsXPStylePrivate::drawBackground(), QRasterPaintEngine::drawCachedGlyphs(), QTextDocumentLayoutPrivate::drawFrameDecoration(), QGraphicsView::drawItems(), QEmulationPaintEngine::drawTextItem(), QPicture::exec(), QEmulationPaintEngine::fill(), fillRegion(), QSvgTinyDocument::mapSourceToTarget(), QDeclarativePaintedItem::paint(), ShaderEffect::prepareBufferedDraw(), QMacCGContext::QMacCGContext(), qt_mac_fill_background(), redirected(), QGraphicsScene::render(), QGraphicsView::render(), QWidgetPrivate::render_helper(), ShaderEffectItem::renderEffect(), restoreRedirected(), setFont(), QPainterReplayer::setupTransform(), and QEmulationPaintEngine::stroke().

1531 {
1532  Q_D(const QPainter);
1533  if (isActive() && d->engine->d_func()->currentClipWidget)
1534  return d->engine->d_func()->currentClipWidget;
1535  return d->original_device;
1536 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
Definition: qpainter.cpp:1545

◆ deviceMatrix()

const QMatrix & QPainter::deviceMatrix ( ) const

Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.

Note
It is advisable to use deviceTransform() instead of this function to preserve the properties of perspective transformations.

This function is only needed when using platform painting commands on the platform dependent handle (Qt::HANDLE), and the platform does not do transformations nativly.

The QPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.

See also
worldMatrix(), QPaintEngine::hasFeature(),

Definition at line 3110 of file qpainter.cpp.

Referenced by QWindowsXPStylePrivate::drawBackgroundDirectly().

3111 {
3112  Q_D(const QPainter);
3113  if (!d->engine) {
3114  qWarning("QPainter::deviceMatrix: Painter not active");
3115  return d->fakeState()->transform.toAffine();
3116  }
3117  return d->state->matrix.toAffine();
3118 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ deviceTransform()

const QTransform & QPainter::deviceTransform ( ) const

Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.

This function is only needed when using platform painting commands on the platform dependent handle (Qt::HANDLE), and the platform does not do transformations nativly.

The QPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.

See also
worldTransform(), QPaintEngine::hasFeature(),

Definition at line 9579 of file qpainter.cpp.

Referenced by QPixmapConvolutionFilter::draw(), QWindowsXPStylePrivate::drawBackground(), QDeclarativePaintedItem::paint(), QMacCGContext::QMacCGContext(), qt_plastique_draw_gradient(), and QWidget::render().

9580 {
9581  Q_D(const QPainter);
9582  if (!d->engine) {
9583  qWarning("QPainter::deviceTransform: Painter not active");
9584  return d->fakeState()->transform;
9585  }
9586  return d->state->matrix;
9587 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ drawArc() [1/3]

void QPainter::drawArc ( const QRectF rectangle,
int  startAngle,
int  spanAngle 
)

Draws the arc defined by the given rectangle, startAngle and spanAngle.

The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. 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.

qpainter-arc.png
QRectF rectangle(10.0, 20.0, 80.0, 60.0);
int startAngle = 30 * 16;
int spanAngle = 120 * 16;
QPainter painter(this);
painter.drawArc(rectangle, startAngle, spanAngle);
See also
drawPie(), drawChord(), {Coordinate System}

Definition at line 4602 of file qpainter.cpp.

Referenced by QCommonStyle::drawComplexControl(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), drawTabShape(), QPicture::exec(), and qDrawRoundedCorners().

4603 {
4604 #ifdef QT_DEBUG_DRAW
4605  if (qt_show_painter_debug_output)
4606  printf("QPainter::drawArc(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n",
4607  r.x(), r.y(), r.width(), r.height(), a/16, alen/16);
4608 #endif
4609  Q_D(QPainter);
4610 
4611  if (!d->engine)
4612  return;
4613 
4614  QRectF rect = r.normalized();
4615 
4616  QPainterPath path;
4617  path.arcMoveTo(rect, a/qreal(16.0));
4618  path.arcTo(rect, a/qreal(16.0), alen/qreal(16.0));
4619  strokePath(path, d->state->pen);
4620 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_D(Class)
Definition: qglobal.h:2482
void arcMoveTo(const QRectF &rect, qreal angle)
Creates a move to that lies on the arc that occupies the given rectangle at angle.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void strokePath(const QPainterPath &path, const QPen &pen)
Draws the outline (strokes) the path path with the pen specified by pen.
Definition: qpainter.cpp:3413
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending...
QRectF normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:1822

◆ drawArc() [2/3]

void QPainter::drawArc ( const QRect rectangle,
int  startAngle,
int  spanAngle 
)
inline

Draws the arc defined by the given rectangle, startAngle and spanAngle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 739 of file qpainter.h.

740 {
741  drawArc(QRectF(r), a, alen);
742 }
void drawArc(const QRectF &rect, int a, int alen)
Draws the arc defined by the given rectangle, startAngle and spanAngle.
Definition: qpainter.cpp:4602
long ASN1_INTEGER_get ASN1_INTEGER * a
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ drawArc() [3/3]

void QPainter::drawArc ( int  x,
int  y,
int  width,
int  height,
int  startAngle,
int  spanAngle 
)
inline

Draws the arc defined by the rectangle beginning at (x, y) with the specified width and height, and the given startAngle and spanAngle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 744 of file qpainter.h.

745 {
746  drawArc(QRectF(x, y, w, h), a, alen);
747 }
void drawArc(const QRectF &rect, int a, int alen)
Draws the arc defined by the given rectangle, startAngle and spanAngle.
Definition: qpainter.cpp:4602
long ASN1_INTEGER_get ASN1_INTEGER * a
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ drawChord() [1/3]

void QPainter::drawChord ( const QRectF rectangle,
int  startAngle,
int  spanAngle 
)

Draws the chord defined by the given rectangle, startAngle and spanAngle.

The chord is filled with the current brush().

The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. 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.

qpainter-chord.png
QRectF rectangle(10.0, 20.0, 80.0, 60.0);
int startAngle = 30 * 16;
int spanAngle = 120 * 16;
QPainter painter(this);
painter.drawChord(rect, startAngle, spanAngle);
See also
drawArc(), drawPie(), {Coordinate System}

Definition at line 4744 of file qpainter.cpp.

Referenced by QPicture::exec().

4745 {
4746 #ifdef QT_DEBUG_DRAW
4747  if (qt_show_painter_debug_output)
4748  printf("QPainter::drawChord(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n",
4749  r.x(), r.y(), r.width(), r.height(), a/16, alen/16);
4750 #endif
4751  Q_D(QPainter);
4752 
4753  if (!d->engine)
4754  return;
4755 
4756  QRectF rect = r.normalized();
4757 
4758  QPainterPath path;
4759  path.arcMoveTo(rect, a/qreal(16.0));
4760  path.arcTo(rect, a/qreal(16.0), alen/qreal(16.0));
4761  path.closeSubpath();
4762  drawPath(path);
4763 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
double qreal
Definition: qglobal.h:1193
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_D(Class)
Definition: qglobal.h:2482
void arcMoveTo(const QRectF &rect, qreal angle)
Creates a move to that lies on the arc that occupies the given rectangle at angle.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending...
QRectF normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:1822

◆ drawChord() [2/3]

void QPainter::drawChord ( int  x,
int  y,
int  width,
int  height,
int  startAngle,
int  spanAngle 
)
inline

Draws the chord defined by the rectangle beginning at (x, y) with the specified width and height, and the given startAngle and spanAngle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 764 of file qpainter.h.

765 {
766  drawChord(QRectF(x, y, w, h), a, alen);
767 }
void drawChord(const QRectF &rect, int a, int alen)
Draws the chord defined by the given rectangle, startAngle and spanAngle.
Definition: qpainter.cpp:4744
long ASN1_INTEGER_get ASN1_INTEGER * a
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ drawChord() [3/3]

void QPainter::drawChord ( const QRect rectangle,
int  startAngle,
int  spanAngle 
)
inline

Draws the chord defined by the given rectangle, startAngle and spanAngle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 759 of file qpainter.h.

760 {
761  drawChord(QRectF(rect), a, alen);
762 }
void drawChord(const QRectF &rect, int a, int alen)
Draws the chord defined by the given rectangle, startAngle and spanAngle.
Definition: qpainter.cpp:4744
long ASN1_INTEGER_get ASN1_INTEGER * a
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ drawConvexPolygon() [1/4]

void QPainter::drawConvexPolygon ( const QPointF points,
int  pointCount 
)

Draws the convex polygon defined by the first pointCount points in the array points using the current pen.

qpainter-polygon.png
static const QPointF points[4] = {
QPointF(10.0, 80.0),
QPointF(20.0, 10.0),
QPointF(80.0, 30.0),
QPointF(90.0, 70.0)
};
QPainter painter(this);
painter.drawConvexPolygon(points, 4);

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, i.e. it contains at least one angle larger than 180 degrees, the results are undefined.

On some platforms (e.g. X11), the drawConvexPolygon() function can be faster than the drawPolygon() function.

See also
drawPolygon(), drawPolyline(), {Coordinate System}

Definition at line 5484 of file qpainter.cpp.

Referenced by QPainterReplayer::process(), and qDrawEdge().

5485 {
5486 #ifdef QT_DEBUG_DRAW
5487  if (qt_show_painter_debug_output)
5488  printf("QPainter::drawConvexPolygon(), count=%d\n", pointCount);
5489 #endif
5490 
5491  Q_D(QPainter);
5492 
5493  if (!d->engine || pointCount < 2)
5494  return;
5495 
5496  if (d->extended) {
5497  d->extended->drawPolygon(points, pointCount, QPaintEngine::ConvexMode);
5498  return;
5499  }
5500 
5501  d->updateState(d->state);
5502 
5503  uint emulationSpecifier = d->state->emulationSpecifier;
5504 
5505  if (emulationSpecifier) {
5506  QPainterPath polygonPath(points[0]);
5507  for (int i=1; i<pointCount; ++i)
5508  polygonPath.lineTo(points[i]);
5509  polygonPath.closeSubpath();
5510  polygonPath.setFillRule(Qt::WindingFill);
5511  d->draw_helper(polygonPath);
5512  return;
5513  }
5514 
5515  d->engine->drawPolygon(points, pointCount, QPaintEngine::ConvexMode);
5516 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
unsigned int uint
Definition: qglobal.h:996

◆ drawConvexPolygon() [2/4]

void QPainter::drawConvexPolygon ( const QPolygonF polygon)
inline

Draws the convex polygon defined by polygon using the current pen and brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 640 of file qpainter.h.

641 {
642  drawConvexPolygon(poly.constData(), poly.size());
643 }
void drawConvexPolygon(const QPointF *points, int pointCount)
Draws the convex polygon defined by the first pointCount points in the array points using the current...
Definition: qpainter.cpp:5484

◆ drawConvexPolygon() [3/4]

void QPainter::drawConvexPolygon ( const QPoint points,
int  pointCount 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the convex polygon defined by the first pointCount points in the array points using the current pen.

Definition at line 5450 of file qpainter.cpp.

5451 {
5452 #ifdef QT_DEBUG_DRAW
5453  if (qt_show_painter_debug_output)
5454  printf("QPainter::drawConvexPolygon(), count=%d\n", pointCount);
5455 #endif
5456 
5457  Q_D(QPainter);
5458 
5459  if (!d->engine || pointCount < 2)
5460  return;
5461 
5462  if (d->extended) {
5463  d->extended->drawPolygon(points, pointCount, QPaintEngine::ConvexMode);
5464  return;
5465  }
5466 
5467  d->updateState(d->state);
5468 
5469  uint emulationSpecifier = d->state->emulationSpecifier;
5470 
5471  if (emulationSpecifier) {
5472  QPainterPath polygonPath(points[0]);
5473  for (int i=1; i<pointCount; ++i)
5474  polygonPath.lineTo(points[i]);
5475  polygonPath.closeSubpath();
5476  polygonPath.setFillRule(Qt::WindingFill);
5477  d->draw_helper(polygonPath);
5478  return;
5479  }
5480 
5481  d->engine->drawPolygon(points, pointCount, QPaintEngine::ConvexMode);
5482 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
unsigned int uint
Definition: qglobal.h:996

◆ drawConvexPolygon() [4/4]

void QPainter::drawConvexPolygon ( const QPolygon polygon)
inline

Draws the convex polygon defined by polygon using the current pen and brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 645 of file qpainter.h.

646 {
647  drawConvexPolygon(poly.constData(), poly.size());
648 }
void drawConvexPolygon(const QPointF *points, int pointCount)
Draws the convex polygon defined by the first pointCount points in the array points using the current...
Definition: qpainter.cpp:5484

◆ drawEllipse() [1/5]

void QPainter::drawEllipse ( const QRectF rectangle)

Draws the ellipse defined by the given rectangle.

A filled ellipse has a size of {rectangle}.QRect::size() . A stroked ellipse has a size of {rectangle}.QRect::size(){size()} plus the pen width.

qpainter-ellipse.png
QRectF rectangle(10.0, 20.0, 80.0, 60.0);
QPainter painter(this);
painter.drawEllipse(rectangle);
See also
drawPie(), {Coordinate System}

Definition at line 4464 of file qpainter.cpp.

Referenced by QSvgEllipse::draw(), QCommonStyle::drawComplexControl(), QCleanlooksStyle::drawControl(), QStyleHelper::drawDial(), QTextDocumentLayoutPrivate::drawListItem(), QPaintEngine::drawPoints(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), drawTabCloseButton(), QPicture::exec(), QGraphicsEllipseItem::paint(), and QPainterReplayer::process().

4465 {
4466 #ifdef QT_DEBUG_DRAW
4467  if (qt_show_painter_debug_output)
4468  printf("QPainter::drawEllipse(), [%.2f,%.2f,%.2f,%.2f]\n", r.x(), r.y(), r.width(), r.height());
4469 #endif
4470  Q_D(QPainter);
4471 
4472  if (!d->engine)
4473  return;
4474 
4475  QRectF rect(r.normalized());
4476 
4477  if (d->extended) {
4478  d->extended->drawEllipse(rect);
4479  return;
4480  }
4481 
4482  d->updateState(d->state);
4483  if (d->state->emulationSpecifier) {
4484  if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
4485  && d->state->matrix.type() == QTransform::TxTranslate) {
4486  rect.translate(QPointF(d->state->matrix.dx(), d->state->matrix.dy()));
4487  } else {
4488  QPainterPath path;
4489  path.addEllipse(rect);
4490  d->draw_helper(path, QPainterPrivate::StrokeAndFillDraw);
4491  return;
4492  }
4493  }
4494 
4495  d->engine->drawEllipse(rect);
4496 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void addEllipse(const QRectF &rect)
Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed...

◆ drawEllipse() [2/5]

void QPainter::drawEllipse ( const QRect rectangle)

Draws the ellipse defined by the given rectangle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4508 of file qpainter.cpp.

4509 {
4510 #ifdef QT_DEBUG_DRAW
4511  if (qt_show_painter_debug_output)
4512  printf("QPainter::drawEllipse(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height());
4513 #endif
4514  Q_D(QPainter);
4515 
4516  if (!d->engine)
4517  return;
4518 
4519  QRect rect(r.normalized());
4520 
4521  if (d->extended) {
4522  d->extended->drawEllipse(rect);
4523  return;
4524  }
4525 
4526  d->updateState(d->state);
4527 
4528  if (d->state->emulationSpecifier) {
4529  if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
4530  && d->state->matrix.type() == QTransform::TxTranslate) {
4531  rect.translate(QPoint(qRound(d->state->matrix.dx()), qRound(d->state->matrix.dy())));
4532  } else {
4533  QPainterPath path;
4534  path.addEllipse(rect);
4535  d->draw_helper(path, QPainterPrivate::StrokeAndFillDraw);
4536  return;
4537  }
4538  }
4539 
4540  d->engine->drawEllipse(rect);
4541 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void addEllipse(const QRectF &rect)
Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed...

◆ drawEllipse() [3/5]

void QPainter::drawEllipse ( int  x,
int  y,
int  width,
int  height 
)
inline

Draws the ellipse defined by the rectangle beginning at ({x}, {y}) with the given width and height.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 724 of file qpainter.h.

725 {
726  drawEllipse(QRect(x, y, w, h));
727 }
void drawEllipse(const QRectF &r)
Draws the ellipse defined by the given rectangle.
Definition: qpainter.cpp:4464
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ drawEllipse() [4/5]

void QPainter::drawEllipse ( const QPointF center,
qreal  rx,
qreal  ry 
)
inline

Draws the ellipse positioned at {center} with radii {rx} and {ry}.

Since
4.4

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 729 of file qpainter.h.

730 {
731  drawEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
732 }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void drawEllipse(const QRectF &r)
Draws the ellipse defined by the given rectangle.
Definition: qpainter.cpp:4464
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ drawEllipse() [5/5]

void QPainter::drawEllipse ( const QPoint center,
int  rx,
int  ry 
)
inline

Draws the ellipse positioned at {center} with radii {rx} and {ry}.

Since
4.4

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 734 of file qpainter.h.

735 {
736  drawEllipse(QRect(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
737 }
void drawEllipse(const QRectF &r)
Draws the ellipse defined by the given rectangle.
Definition: qpainter.cpp:4464
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ drawGlyphRun()

void QPainter::drawGlyphRun ( const QPointF position,
const QGlyphRun glyphs 
)

Draws the specified glyphs at the given position.

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.

Since
4.8
See also
QGlyphRun::setRawFont(), QGlyphRun::setPositions(), QGlyphRun::setGlyphIndexes()

Definition at line 6064 of file qpainter.cpp.

Referenced by QPainterReplayer::process().

6065 {
6066  Q_D(QPainter);
6067 
6068  QRawFont font = glyphRun.rawFont();
6069  if (!font.isValid())
6070  return;
6071 
6072  QGlyphRunPrivate *glyphRun_d = QGlyphRunPrivate::get(glyphRun);
6073 
6074  const quint32 *glyphIndexes = glyphRun_d->glyphIndexData;
6075  const QPointF *glyphPositions = glyphRun_d->glyphPositionData;
6076 
6077  int count = qMin(glyphRun_d->glyphIndexDataSize, glyphRun_d->glyphPositionDataSize);
6078  QVarLengthArray<QFixedPoint, 128> fixedPointPositions(count);
6079 
6080  QRawFontPrivate *fontD = QRawFontPrivate::get(font);
6081  bool supportsTransformations;
6082  if (d->extended != 0) {
6083  supportsTransformations = d->extended->supportsTransformations(fontD->fontEngine->fontDef.pixelSize,
6084  d->state->matrix);
6085  } else {
6086  supportsTransformations = d->engine->type() == QPaintEngine::CoreGraphics
6087  || d->state->matrix.isAffine();
6088  }
6089 
6090  for (int i=0; i<count; ++i) {
6091  QPointF processedPosition = position + glyphPositions[i];
6092  if (!supportsTransformations)
6093  processedPosition = d->state->transform().map(processedPosition);
6094  fixedPointPositions[i] = QFixedPoint::fromPointF(processedPosition);
6095  }
6096 
6097  d->drawGlyphs(glyphIndexes, fixedPointPositions.data(), count, font, glyphRun.overline(),
6098  glyphRun.underline(), glyphRun.strikeOut());
6099 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
bool isValid() const
Returns true if the QRawFont is valid and false otherwise.
Definition: qrawfont.cpp:196
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static QRawFontPrivate * get(const QRawFont &font)
Definition: qrawfont_p.h:109
#define Q_D(Class)
Definition: qglobal.h:2482
static QFixedPoint fromPointF(const QPointF &p)
Definition: qfixed_p.h:195
const quint32 * glyphIndexData
Definition: qglyphrun_p.h:104
static QGlyphRunPrivate * get(const QGlyphRun &glyphRun)
Definition: qglyphrun_p.h:110
bool overline() const
Returns true if overline has been set; otherwise returns false.
Definition: qfont.cpp:1344
const QFont & font() const
Returns the currently set font used for drawing text.
Definition: qpainter.cpp:4312
qreal pixelSize
Definition: qfont_p.h:90
const QPointF * glyphPositionData
Definition: qglyphrun_p.h:107
The QRawFont class provides access to a single physical instance of a font.
Definition: qrawfont.h:63
unsigned int quint32
Definition: qglobal.h:938
QFontEngine * fontEngine
Definition: qrawfont_p.h:111
QFontDef fontDef

◆ drawImage() [1/9]

void QPainter::drawImage ( const QRectF targetRect,
const QImage image,
const QRectF sourceRect,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
)

Definition at line 5936 of file qpainter.cpp.

Referenced by blendCursor(), buttonChange(), QLinuxFbScreen::doRedraw(), QFbScreen::doRedraw(), QSvgImage::draw(), QPixmapConvolutionFilter::draw(), QPixmapColorizeFilter::draw(), QPixmapDropShadowFilter::draw(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QWindowsVistaAnimation::drawBlendedImage(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QPlatformSoftwareCursor::drawCursor(), QTextImageHandler::drawObject(), QWindowsMobileStylePrivate::drawPanelItemViewSelected(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsMobileStylePrivate::drawScrollbarGrip(), QWindowsMobileStylePrivate::drawScrollbarHandleDown(), QWindowsMobileStylePrivate::drawScrollbarHandleUp(), QWindowsMobileStylePrivate::drawTabBarTab(), QPicture::exec(), operator>>(), QBlittablePixmapData::paintEngine(), QPainterReplayer::process(), qt_blurImage(), qt_plastique_draw_handle(), toVGImageWithOpacity(), toVGImageWithOpacitySubRect(), and QImage::transformed().

5938 {
5939  Q_D(QPainter);
5940 
5941  if (!d->engine || image.isNull())
5942  return;
5943 
5944  qreal x = targetRect.x();
5945  qreal y = targetRect.y();
5946  qreal w = targetRect.width();
5947  qreal h = targetRect.height();
5948  qreal sx = sourceRect.x();
5949  qreal sy = sourceRect.y();
5950  qreal sw = sourceRect.width();
5951  qreal sh = sourceRect.height();
5952 
5953  // Sanity-check clipping
5954  if (sw <= 0)
5955  sw = image.width() - sx;
5956 
5957  if (sh <= 0)
5958  sh = image.height() - sy;
5959 
5960  if (w < 0)
5961  w = sw;
5962  if (h < 0)
5963  h = sh;
5964 
5965  if (sx < 0) {
5966  qreal w_ratio = sx * w/sw;
5967  x -= w_ratio;
5968  w += w_ratio;
5969  sw += sx;
5970  sx = 0;
5971  }
5972 
5973  if (sy < 0) {
5974  qreal h_ratio = sy * h/sh;
5975  y -= h_ratio;
5976  h += h_ratio;
5977  sh += sy;
5978  sy = 0;
5979  }
5980 
5981  if (sw + sx > image.width()) {
5982  qreal delta = sw - (image.width() - sx);
5983  qreal w_ratio = delta * w/sw;
5984  sw -= delta;
5985  w -= w_ratio;
5986  }
5987 
5988  if (sh + sy > image.height()) {
5989  qreal delta = sh - (image.height() - sy);
5990  qreal h_ratio = delta * h/sh;
5991  sh -= delta;
5992  h -= h_ratio;
5993  }
5994 
5995  if (w == 0 || h == 0 || sw <= 0 || sh <= 0)
5996  return;
5997 
5998  if (d->extended) {
5999  d->extended->drawImage(QRectF(x, y, w, h), image, QRectF(sx, sy, sw, sh), flags);
6000  return;
6001  }
6002 
6003  d->updateState(d->state);
6004 
6005  if (((d->state->matrix.type() > QTransform::TxTranslate || (sw != w || sh != h))
6006  && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
6007  || (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
6008  || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
6009  {
6010  save();
6011  // If there is no rotation involved we have to make sure we use the
6012  // antialiased and not the aliased coordinate system by rounding the coordinates.
6013  if (d->state->matrix.type() <= QTransform::TxScale) {
6014  const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
6015  x = p.x();
6016  y = p.y();
6017  }
6018 
6019  if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) {
6020  sx = qRound(sx);
6021  sy = qRound(sy);
6022  sw = qRound(sw);
6023  sh = qRound(sh);
6024  }
6025  translate(x, y);
6026  scale(w / sw, h / sh);
6029  QBrush brush(image);
6030  setBrush(brush);
6031  setPen(Qt::NoPen);
6032  setBrushOrigin(QPointF(-sx, -sy));
6033 
6034  drawRect(QRectF(0, 0, sw, sh));
6035  restore();
6036  return;
6037  }
6038 
6039  if (d->state->matrix.type() == QTransform::TxTranslate
6040  && !d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
6041  x += d->state->matrix.dx();
6042  y += d->state->matrix.dy();
6043  }
6044 
6045  d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(sx, sy, sw, sh), flags);
6046 }
void setBackgroundMode(Qt::BGMode mode)
Sets the background mode of the painter to the given mode.
Definition: qpainter.cpp:3998
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
double qreal
Definition: qglobal.h:1193
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
#define Q_D(Class)
Definition: qglobal.h:2482
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QPointF roundInDeviceCoordinates(const QPointF &p, const QTransform &m)
Definition: qpainter.cpp:5518
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
Definition: qpainter.cpp:3234
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ drawImage() [2/9]

void QPainter::drawImage ( const QRect targetRect,
const QImage image,
const QRect sourceRect,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
)
inline

Definition at line 897 of file qpainter.h.

899 {
900  drawImage(QRectF(targetRect), image, QRectF(sourceRect), flags);
901 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936

◆ drawImage() [3/9]

void QPainter::drawImage ( const QPointF p,
const QImage image,
const QRectF sr,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
)
inline

Definition at line 903 of file qpainter.h.

905 {
906  drawImage(QRectF(p.x(), p.y(), -1, -1), image, sr, flags);
907 }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ drawImage() [4/9]

void QPainter::drawImage ( const QPoint p,
const QImage image,
const QRect sr,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
)
inline

Definition at line 909 of file qpainter.h.

911 {
912  drawImage(QRect(p.x(), p.y(), -1, -1), image, sr, flags);
913 }
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ drawImage() [5/9]

void QPainter::drawImage ( const QRectF rectangle,
const QImage image 
)
inline

Draws the given image into the given rectangle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note
The image is scaled to fit the rectangle, if both the image and rectangle size disagree.

Definition at line 916 of file qpainter.h.

917 {
918  drawImage(r, image, QRect(0, 0, image.width(), image.height()));
919 }
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936

◆ drawImage() [6/9]

void QPainter::drawImage ( const QRect rectangle,
const QImage image 
)
inline

Draws the given image into the given rectangle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note
The image is scaled to fit the rectangle, if both the image and rectangle size disagree.

Definition at line 921 of file qpainter.h.

922 {
923  drawImage(r, image, QRectF(0, 0, image.width(), image.height()));
924 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936

◆ drawImage() [7/9]

void QPainter::drawImage ( const QPointF point,
const QImage image 
)

Draws the given image at the given point.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 5881 of file qpainter.cpp.

5882 {
5883  Q_D(QPainter);
5884 
5885  if (!d->engine || image.isNull())
5886  return;
5887 
5888  if (d->extended) {
5889  d->extended->drawImage(p, image);
5890  return;
5891  }
5892 
5893  qreal x = p.x();
5894  qreal y = p.y();
5895 
5896  int w = image.width();
5897  int h = image.height();
5898 
5899  d->updateState(d->state);
5900 
5901  if (((d->state->matrix.type() > QTransform::TxTranslate)
5902  && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
5903  || (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
5904  || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
5905  {
5906  save();
5907  // If there is no rotation involved we have to make sure we use the
5908  // antialiased and not the aliased coordinate system by rounding the coordinates.
5909  if (d->state->matrix.type() <= QTransform::TxScale) {
5910  const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
5911  x = p.x();
5912  y = p.y();
5913  }
5914  translate(x, y);
5917  QBrush brush(image);
5918  setBrush(brush);
5919  setPen(Qt::NoPen);
5920  setBrushOrigin(QPointF(0, 0));
5921 
5922  drawRect(image.rect());
5923  restore();
5924  return;
5925  }
5926 
5927  if (d->state->matrix.type() == QTransform::TxTranslate
5928  && !d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
5929  x += d->state->matrix.dx();
5930  y += d->state->matrix.dy();
5931  }
5932 
5933  d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(0, 0, w, h), Qt::AutoColor);
5934 }
void setBackgroundMode(Qt::BGMode mode)
Sets the background mode of the painter to the given mode.
Definition: qpainter.cpp:3998
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
Definition: qimage.cpp:1603
#define Q_D(Class)
Definition: qglobal.h:2482
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QPointF roundInDeviceCoordinates(const QPointF &p, const QTransform &m)
Definition: qpainter.cpp:5518
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ drawImage() [8/9]

void QPainter::drawImage ( const QPoint point,
const QImage image 
)
inline

Draws the given image at the given point.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 926 of file qpainter.h.

927 {
928  drawImage(QPointF(p), image);
929 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936

◆ drawImage() [9/9]

void QPainter::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 
)
inline

Definition at line 931 of file qpainter.h.

933 {
934  if (sx == 0 && sy == 0 && sw == -1 && sh == -1 && flags == Qt::AutoColor)
935  drawImage(QPointF(x, y), image);
936  else
937  drawImage(QRectF(x, y, -1, -1), image, QRectF(sx, sy, sw, sh), flags);
938 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936

◆ drawLine() [1/5]

void QPainter::drawLine ( const QLineF line)
inline

Draws a line defined by line.

qpainter-line.png
QLineF line(10.0, 80.0, 90.0, 20.0);
QPainter(this);
painter.drawLine(line);
See also
drawLines(), drawPolyline(), {Coordinate System}

Definition at line 573 of file qpainter.h.

Referenced by QSvgLine::draw(), QPainterPrivate::draw_helper(), QTextDocumentLayoutPrivate::drawBlock(), QCommonStyle::drawComplexControl(), QWindowsCEStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QTextLayout::drawCursor(), QStyleHelper::drawDial(), QPlastiqueStylePrivate::drawPartialFrame(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QWindowsMobileStylePrivate::drawScrollbarGrip(), QWindowsMobileStylePrivate::drawScrollbarHandleDown(), QWindowsMobileStylePrivate::drawScrollbarHandleUp(), QWindowsMobileStylePrivate::drawTabBarTab(), drawTabBase(), drawTabCloseButton(), drawTabShape(), drawTextItemDecoration(), QPicture::exec(), QScriptEdit::extraAreaPaintEvent(), QTriangulator< T >::ComplexToSimple::Event::operator<(), QGraphicsLineItem::paint(), QWellArray::paintCellContents(), QTableView::paintEvent(), QPagePreview::paintEvent(), QWhatsThat::paintEvent(), QWizardHeader::paintEvent(), QWizardAntiFlickerWidget::paintEvent(), qDrawEdge(), qDrawPlainRect(), qDrawShadeLine(), and qt_cleanlooks_draw_mdibutton().

574 {
575  drawLines(&l, 1);
576 }
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
QFactoryLoader * l

◆ drawLine() [2/5]

void QPainter::drawLine ( const QLine line)
inline

Draws a line defined by line.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 578 of file qpainter.h.

579 {
580  drawLines(&line, 1);
581 }
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873

◆ drawLine() [3/5]

void QPainter::drawLine ( int  x1,
int  y1,
int  x2,
int  y2 
)
inline

Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 583 of file qpainter.h.

584 {
585  QLine l(x1, y1, x2, y2);
586  drawLines(&l, 1);
587 }
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
QFactoryLoader * l

◆ drawLine() [4/5]

void QPainter::drawLine ( const QPoint p1,
const QPoint p2 
)
inline

Draws a line from p1 to p2.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 589 of file qpainter.h.

590 {
591  QLine l(p1, p2);
592  drawLines(&l, 1);
593 }
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
QFactoryLoader * l

◆ drawLine() [5/5]

void QPainter::drawLine ( const QPointF p1,
const QPointF p2 
)
inline

Draws a line from p1 to p2.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 595 of file qpainter.h.

596 {
597  drawLine(QLineF(p1, p2));
598 }
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212

◆ drawLines() [1/8]

void QPainter::drawLines ( const QLineF lines,
int  lineCount 
)

Draws the first lineCount lines in the array lines using the current pen.

See also
drawLine(), drawPolyline()

Definition at line 4873 of file qpainter.cpp.

Referenced by QCommonStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QStyleHelper::drawDial(), drawLines(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QPicture::exec(), QPainterReplayer::process(), qDrawPlainRect(), qDrawShadePanel(), qDrawShadeRect(), qt_cleanlooks_draw_mdibutton(), qt_plastique_draw_frame(), qt_plastique_draw_mdibutton(), and qt_plastique_drawFrame().

4874 {
4875 #ifdef QT_DEBUG_DRAW
4876  if (qt_show_painter_debug_output)
4877  printf("QPainter::drawLines(), line count=%d\n", lineCount);
4878 #endif
4879 
4880  Q_D(QPainter);
4881 
4882  if (!d->engine || lineCount < 1)
4883  return;
4884 
4885  if (d->extended) {
4886  d->extended->drawLines(lines, lineCount);
4887  return;
4888  }
4889 
4890  d->updateState(d->state);
4891 
4892  uint lineEmulation = line_emulation(d->state->emulationSpecifier);
4893 
4894  if (lineEmulation) {
4895  if (lineEmulation == QPaintEngine::PrimitiveTransform
4896  && d->state->matrix.type() == QTransform::TxTranslate) {
4897  for (int i = 0; i < lineCount; ++i) {
4898  QLineF line = lines[i];
4899  line.translate(d->state->matrix.dx(), d->state->matrix.dy());
4900  d->engine->drawLines(&line, 1);
4901  }
4902  } else {
4903  QPainterPath linePath;
4904  for (int i = 0; i < lineCount; ++i) {
4905  linePath.moveTo(lines[i].p1());
4906  linePath.lineTo(lines[i].p2());
4907  }
4908  d->draw_helper(linePath, QPainterPrivate::StrokeDraw);
4909  }
4910  return;
4911  }
4912  d->engine->drawLines(lines, lineCount);
4913 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
static uint line_emulation(uint emulation)
Definition: qpainter.cpp:143
void translate(const QPointF &p)
Translates this line by the given offset.
Definition: qline.h:339
unsigned int uint
Definition: qglobal.h:996

◆ drawLines() [2/8]

void QPainter::drawLines ( const QVector< QLineF > &  lines)
inline

Draws the set of lines defined by the list lines using the current pen and brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 600 of file qpainter.h.

601 {
602  drawLines(lines.constData(), lines.size());
603 }
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ drawLines() [3/8]

void QPainter::drawLines ( const QPointF pointPairs,
int  lineCount 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the first lineCount lines in the array pointPairs using the current pen.

The lines are specified as pairs of points so the number of entries in pointPairs must be at least lineCount * 2.

Definition at line 4972 of file qpainter.cpp.

4973 {
4974  Q_ASSERT(sizeof(QLineF) == 2*sizeof(QPointF));
4975 
4976  drawLines((QLineF*)pointPairs, lineCount);
4977 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873

◆ drawLines() [4/8]

void QPainter::drawLines ( const QVector< QPointF > &  pointPairs)
inline

Draws a line for each pair of points in the vector pointPairs using the current pen.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

If there is an odd number of points in the array, the last point will be ignored.

Definition at line 610 of file qpainter.h.

611 {
612  drawLines(pointPairs.constData(), pointPairs.size() / 2);
613 }
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ drawLines() [5/8]

void QPainter::drawLines ( const QLine lines,
int  lineCount 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the first lineCount lines in the array lines using the current pen.

Definition at line 4922 of file qpainter.cpp.

4923 {
4924 #ifdef QT_DEBUG_DRAW
4925  if (qt_show_painter_debug_output)
4926  printf("QPainter::drawLine(), line count=%d\n", lineCount);
4927 #endif
4928 
4929  Q_D(QPainter);
4930 
4931  if (!d->engine || lineCount < 1)
4932  return;
4933 
4934  if (d->extended) {
4935  d->extended->drawLines(lines, lineCount);
4936  return;
4937  }
4938 
4939  d->updateState(d->state);
4940 
4941  uint lineEmulation = line_emulation(d->state->emulationSpecifier);
4942 
4943  if (lineEmulation) {
4944  if (lineEmulation == QPaintEngine::PrimitiveTransform
4945  && d->state->matrix.type() == QTransform::TxTranslate) {
4946  for (int i = 0; i < lineCount; ++i) {
4947  QLineF line = lines[i];
4948  line.translate(d->state->matrix.dx(), d->state->matrix.dy());
4949  d->engine->drawLines(&line, 1);
4950  }
4951  } else {
4952  QPainterPath linePath;
4953  for (int i = 0; i < lineCount; ++i) {
4954  linePath.moveTo(lines[i].p1());
4955  linePath.lineTo(lines[i].p2());
4956  }
4957  d->draw_helper(linePath, QPainterPrivate::StrokeDraw);
4958  }
4959  return;
4960  }
4961  d->engine->drawLines(lines, lineCount);
4962 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
static uint line_emulation(uint emulation)
Definition: qpainter.cpp:143
void translate(const QPointF &p)
Translates this line by the given offset.
Definition: qline.h:339
unsigned int uint
Definition: qglobal.h:996

◆ drawLines() [6/8]

void QPainter::drawLines ( const QVector< QLine > &  lines)
inline

Draws the set of lines defined by the list lines using the current pen and brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 605 of file qpainter.h.

606 {
607  drawLines(lines.constData(), lines.size());
608 }
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ drawLines() [7/8]

void QPainter::drawLines ( const QPoint pointPairs,
int  lineCount 
)

Draws the first lineCount lines in the array pointPairs using the current pen.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4988 of file qpainter.cpp.

4989 {
4990  Q_ASSERT(sizeof(QLine) == 2*sizeof(QPoint));
4991 
4992  drawLines((QLine*)pointPairs, lineCount);
4993 }
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ drawLines() [8/8]

void QPainter::drawLines ( const QVector< QPoint > &  pointPairs)
inline

Draws a line for each pair of points in the vector pointPairs using the current pen.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 615 of file qpainter.h.

616 {
617  drawLines(pointPairs.constData(), pointPairs.size() / 2);
618 }
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ drawPath()

void QPainter::drawPath ( const QPainterPath path)

Draws the given painter path using the current pen for outline and the current brush for filling.

qpainter-path.png
path.moveTo(20, 80);
path.lineTo(20, 30);
path.cubicTo(80, 0, 50, 50, 80, 80);
QPainter painter(this);
painter.drawPath(path);
See also
{painting/painterpaths}{the Painter Paths example},{demos/deform}{the Vector Deformation demo}

Definition at line 3502 of file qpainter.cpp.

Referenced by QFontEngine::alphaMapForGlyph(), alphaMapFromPath(), QBalloonTip::balloon(), QSvgArc::draw(), QSvgFont::draw(), QSvgPath::draw(), QTextLayout::draw(), QTextLine::draw(), QPainterPrivate::draw_helper(), drawChord(), QPlastiqueStyle::drawComplexControl(), QCommonStyle::drawControl(), QX11PaintEngine::drawFreetype(), drawPie(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QMacStyle::drawPrimitive(), drawRoundedRect(), QPicture::exec(), fillPath(), generateWavyPixmap(), QGraphicsPathItem::paint(), QPainterReplayer::process(), and strokePath().

3503 {
3504 #ifdef QT_DEBUG_DRAW
3505  QRectF pathBounds = path.boundingRect();
3506  if (qt_show_painter_debug_output)
3507  printf("QPainter::drawPath(), size=%d, [%.2f,%.2f,%.2f,%.2f]\n",
3508  path.elementCount(),
3509  pathBounds.x(), pathBounds.y(), pathBounds.width(), pathBounds.height());
3510 #endif
3511 
3512  Q_D(QPainter);
3513 
3514  if (!d->engine) {
3515  qWarning("QPainter::drawPath: Painter not active");
3516  return;
3517  }
3518 
3519  if (d->extended) {
3520  d->extended->drawPath(path);
3521  return;
3522  }
3523  d->updateState(d->state);
3524 
3525  if (d->engine->hasFeature(QPaintEngine::PainterPaths) && d->state->emulationSpecifier == 0) {
3526  d->engine->drawPath(path);
3527  } else {
3528  d->draw_helper(path);
3529  }
3530 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
#define Q_D(Class)
Definition: qglobal.h:2482
QRectF boundingRect() const
Returns the bounding rectangle of this painter path as a rectangle with floating point precision...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
Q_CORE_EXPORT void qWarning(const char *,...)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ drawPicture() [1/3]

void QPainter::drawPicture ( const QPointF point,
const QPicture picture 
)

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).

QPicture picture;
QPointF point(10.0, 20.0)
picture.load("drawing.pic");
QPainter painter(this);
painter.drawPicture(0, 0, picture);
See also
QPicture::play()

Definition at line 7282 of file qpainter.cpp.

Referenced by QAlphaPaintEnginePrivate::drawAlphaImage(), QAlphaPaintEngine::flushAndInit(), and QLabel::paintEvent().

7283 {
7284  Q_D(QPainter);
7285 
7286  if (!d->engine)
7287  return;
7288 
7289  if (!d->extended)
7290  d->updateState(d->state);
7291 
7292  save();
7293  translate(p);
7294  const_cast<QPicture *>(&picture)->play(this);
7295  restore();
7296 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
#define Q_D(Class)
Definition: qglobal.h:2482
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
The QPicture class is a paint device that records and replays QPainter commands.
Definition: qpicture.h:58
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ drawPicture() [2/3]

void QPainter::drawPicture ( int  x,
int  y,
const QPicture picture 
)
inline

Draws the given picture at point (x, y).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 996 of file qpainter.h.

997 {
998  drawPicture(QPoint(x, y), p);
999 }
void drawPicture(const QPointF &p, const QPicture &picture)
Replays the given picture at the given point.
Definition: qpainter.cpp:7282
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ drawPicture() [3/3]

void QPainter::drawPicture ( const QPoint point,
const QPicture picture 
)
inline

Replays the given picture at the given point.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1001 of file qpainter.h.

1002 {
1003  drawPicture(QPointF(pt), p);
1004 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawPicture(const QPointF &p, const QPicture &picture)
Replays the given picture at the given point.
Definition: qpainter.cpp:7282

◆ drawPie() [1/3]

void QPainter::drawPie ( const QRectF rectangle,
int  startAngle,
int  spanAngle 
)

Draws a pie defined by the given rectangle, startAngle and and spanAngle.

The pie is filled with the current brush().

The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. 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.

qpainter-pie.png
QRectF rectangle(10.0, 20.0, 80.0, 60.0);
int startAngle = 30 * 16;
int spanAngle = 120 * 16;
QPainter painter(this);
painter.drawPie(rectangle, startAngle, spanAngle);
See also
drawEllipse(), drawChord(), {Coordinate System}

Definition at line 4670 of file qpainter.cpp.

Referenced by QPicture::exec(), and QGraphicsEllipseItem::paint().

4671 {
4672 #ifdef QT_DEBUG_DRAW
4673  if (qt_show_painter_debug_output)
4674  printf("QPainter::drawPie(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n",
4675  r.x(), r.y(), r.width(), r.height(), a/16, alen/16);
4676 #endif
4677  Q_D(QPainter);
4678 
4679  if (!d->engine)
4680  return;
4681 
4682  if (a > (360*16)) {
4683  a = a % (360*16);
4684  } else if (a < 0) {
4685  a = a % (360*16);
4686  if (a < 0) a += (360*16);
4687  }
4688 
4689  QRectF rect = r.normalized();
4690 
4691  QPainterPath path;
4692  path.moveTo(rect.center());
4693  path.arcTo(rect.x(), rect.y(), rect.width(), rect.height(), a/qreal(16.0), alen/qreal(16.0));
4694  path.closeSubpath();
4695  drawPath(path);
4696 
4697 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
double qreal
Definition: qglobal.h:1193
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_D(Class)
Definition: qglobal.h:2482
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending...
QRectF normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:1822
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686

◆ drawPie() [2/3]

void QPainter::drawPie ( int  x,
int  y,
int  w,
int  h,
int  a,
int  alen 
)
inline

Definition at line 754 of file qpainter.h.

755 {
756  drawPie(QRectF(x, y, w, h), a, alen);
757 }
void drawPie(const QRectF &rect, int a, int alen)
Draws a pie defined by the given rectangle, startAngle and and spanAngle.
Definition: qpainter.cpp:4670
long ASN1_INTEGER_get ASN1_INTEGER * a
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ drawPie() [3/3]

void QPainter::drawPie ( const QRect rectangle,
int  startAngle,
int  spanAngle 
)
inline

Draws a pie defined by the given rectangle, startAngle and and spanAngle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 749 of file qpainter.h.

750 {
751  drawPie(QRectF(rect), a, alen);
752 }
void drawPie(const QRectF &rect, int a, int alen)
Draws a pie defined by the given rectangle, startAngle and and spanAngle.
Definition: qpainter.cpp:4670
long ASN1_INTEGER_get ASN1_INTEGER * a
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ drawPixmap() [1/11]

void QPainter::drawPixmap ( const QRectF target,
const QPixmap pixmap,
const QRectF source 
)

Draws the rectangular portion source of the given pixmap into the given target in the paint device.

Note
The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
QRectF target(10.0, 20.0, 80.0, 60.0);
QRectF source(0.0, 0.0, 70.0, 40.0);
QPixmap pixmap(":myPixmap.png");
QPainter(this);
painter.drawPixmap(target, image, source);

If pixmap is a QBitmap it is drawn with the bits that are "set" using the pens 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.

See also
drawImage()

Definition at line 5619 of file qpainter.cpp.

Referenced by _q_paintIntoCache(), QOleDropSource::createCursors(), QPixmap::depth(), QGraphicsEffectSource::draw(), QGraphicsShaderEffect::draw(), QVGPixmapDropShadowFilter::draw(), QPixmapBlurFilter::draw(), QPixmapColorizeFilter::draw(), QPixmapDropShadowFilter::draw(), QGraphicsOpacityEffect::draw(), QTreeViewPrivate::drawAnimatedOperation(), QRenderRule::drawBackgroundImage(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QStyleHelper::drawBorderPixmap(), QMacStylePrivate::drawColorlessButton(), QMacStylePrivate::drawCombobox(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QItemDelegate::drawDecoration(), QGraphicsScenePrivate::drawItemHelper(), QStyle::drawItemPixmap(), QTextImageHandler::drawObject(), QDeclarativeTextPrivate::drawOutline(), QOpenGLPaintEngine::drawPixmap(), QCommonStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMacStylePrivate::drawTableHeader(), QPSPrintEngine::drawTiledPixmap(), QOpenGLPaintEngine::drawTiledPixmap(), QSplashScreen::event(), QPicture::exec(), QPainterState::init(), QMacPixmapData::macCreatePixels(), QSvgIconEngine::paint(), QDeclarativeImage::paint(), QDeclarativePaintedItem::paint(), QPixmapIconEngine::paint(), QIconLoaderEngine::paint(), QDeclarativeText::paint(), QGraphicsPixmapItem::paint(), QGtkPainter::paintArrow(), QGtkPainter::paintBox(), QGtkPainter::paintBoxGap(), QDecorationWindows::paintButton(), QDecorationDefault::paintButton(), QGtkPainter::paintCheckbox(), QAlphaWidget::paintEvent(), QCommandLinkButton::paintEvent(), QShapedPixmapWidget::paintEvent(), QBalloonTip::paintEvent(), QAxHostWidget::paintEvent(), QWhatsThat::paintEvent(), QWizard::paintEvent(), QGraphicsView::paintEvent(), QWizardHeader::paintEvent(), QRollEffect::paintEvent(), QMdi::ControlLabel::paintEvent(), QColorPicker::paintEvent(), QColorLuminancePicker::paintEvent(), QGtkPainter::paintExpander(), QGtkPainter::paintExtention(), QGtkPainter::paintFlatBox(), QGtkPainter::paintFocus(), QGtkPainter::paintHandle(), QGtkPainter::paintHline(), QGtkPainter::paintOption(), QGtkPainter::paintResizeGrip(), QGtkPainter::paintShadow(), QGtkPainter::paintSlider(), QGtkPainter::paintVline(), QGraphicsWidget::paintWindowFrame(), QPainterReplayer::process(), QGLPixmapColorizeFilter::processGL(), QGLPixmapConvolutionFilter::processGL(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), qDrawPlainRect(), qt_fill_tile(), qt_mac_constructQIconFromIconRef(), qt_mac_grabDisplayRect(), qt_plastique_draw_gradient(), QWidgetPrivate::render_helper(), QPixmap::scroll(), QWindowsStyle::standardIconImplementation(), QCommonStyle::standardIconImplementation(), QMacStyle::standardIconImplementation(), QCommonStyle::standardPixmap(), and QWindowsStyle::standardPixmap().

5620 {
5621 #if defined QT_DEBUG_DRAW
5622  if (qt_show_painter_debug_output)
5623  printf("QPainter::drawPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], source=[%.2f,%.2f,%.2f,%.2f]\n",
5624  r.x(), r.y(), r.width(), r.height(),
5625  pm.width(), pm.height(),
5626  sr.x(), sr.y(), sr.width(), sr.height());
5627 #endif
5628 
5629  Q_D(QPainter);
5630  if (!d->engine || pm.isNull())
5631  return;
5632 #ifndef QT_NO_DEBUG
5633  qt_painter_thread_test(d->device->devType(), "drawPixmap()", true);
5634 #endif
5635 
5636  qreal x = r.x();
5637  qreal y = r.y();
5638  qreal w = r.width();
5639  qreal h = r.height();
5640  qreal sx = sr.x();
5641  qreal sy = sr.y();
5642  qreal sw = sr.width();
5643  qreal sh = sr.height();
5644 
5645  // Sanity-check clipping
5646  if (sw <= 0)
5647  sw = pm.width() - sx;
5648 
5649  if (sh <= 0)
5650  sh = pm.height() - sy;
5651 
5652  if (w < 0)
5653  w = sw;
5654  if (h < 0)
5655  h = sh;
5656 
5657  if (sx < 0) {
5658  qreal w_ratio = sx * w/sw;
5659  x -= w_ratio;
5660  w += w_ratio;
5661  sw += sx;
5662  sx = 0;
5663  }
5664 
5665  if (sy < 0) {
5666  qreal h_ratio = sy * h/sh;
5667  y -= h_ratio;
5668  h += h_ratio;
5669  sh += sy;
5670  sy = 0;
5671  }
5672 
5673  if (sw + sx > pm.width()) {
5674  qreal delta = sw - (pm.width() - sx);
5675  qreal w_ratio = delta * w/sw;
5676  sw -= delta;
5677  w -= w_ratio;
5678  }
5679 
5680  if (sh + sy > pm.height()) {
5681  qreal delta = sh - (pm.height() - sy);
5682  qreal h_ratio = delta * h/sh;
5683  sh -= delta;
5684  h -= h_ratio;
5685  }
5686 
5687  if (w == 0 || h == 0 || sw <= 0 || sh <= 0)
5688  return;
5689 
5690  if (d->extended) {
5691  d->extended->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh));
5692  return;
5693  }
5694 
5695  // Emulate opaque background for bitmaps
5696  if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap())
5697  fillRect(QRectF(x, y, w, h), d->state->bgBrush.color());
5698 
5699  d->updateState(d->state);
5700 
5701  if ((d->state->matrix.type() > QTransform::TxTranslate
5702  && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
5703  || (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
5704  || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))
5705  || ((sw != w || sh != h) && !d->engine->hasFeature(QPaintEngine::PixmapTransform)))
5706  {
5707  save();
5708  // If there is no rotation involved we have to make sure we use the
5709  // antialiased and not the aliased coordinate system by rounding the coordinates.
5710  if (d->state->matrix.type() <= QTransform::TxScale) {
5711  const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
5712  x = p.x();
5713  y = p.y();
5714  }
5715 
5716  if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) {
5717  sx = qRound(sx);
5718  sy = qRound(sy);
5719  sw = qRound(sw);
5720  sh = qRound(sh);
5721  }
5722 
5723  translate(x, y);
5724  scale(w / sw, h / sh);
5727  QBrush brush;
5728 
5729  if (sw == pm.width() && sh == pm.height())
5730  brush = QBrush(d->state->pen.color(), pm);
5731  else
5732  brush = QBrush(d->state->pen.color(), pm.copy(sx, sy, sw, sh));
5733 
5734  setBrush(brush);
5735  setPen(Qt::NoPen);
5736 
5737  drawRect(QRectF(0, 0, sw, sh));
5738  restore();
5739  } else {
5740  if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
5741  x += d->state->matrix.dx();
5742  y += d->state->matrix.dy();
5743  }
5744  d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh));
5745  }
5746 }
void setBackgroundMode(Qt::BGMode mode)
Sets the background mode of the painter to the given mode.
Definition: qpainter.cpp:3998
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
#define Q_D(Class)
Definition: qglobal.h:2482
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QPointF roundInDeviceCoordinates(const QPointF &p, const QTransform &m)
Definition: qpainter.cpp:5518
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
static bool qt_painter_thread_test(int devType, const char *what, bool extraCondition=false)
Definition: qpainter.cpp:156
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
Definition: qpainter.cpp:3234
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ drawPixmap() [2/11]

void QPainter::drawPixmap ( const QRect target,
const QPixmap pixmap,
const QRect source 
)
inline

Draws the rectangular portion source of the given pixmap into the given target in the paint device.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note
The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.

Definition at line 845 of file qpainter.h.

846 {
847  drawPixmap(QRectF(targetRect), pixmap, QRectF(sourceRect));
848 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619

◆ drawPixmap() [3/11]

void QPainter::drawPixmap ( int  x,
int  y,
int  w,
int  h,
const QPixmap pixmap,
int  sx,
int  sy,
int  sw,
int  sh 
)
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 a width of w and a height of h.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

If sw or sh are equal to zero the width/height of the pixmap is used and adjusted by the offset sx/sy;

Definition at line 870 of file qpainter.h.

872 {
873  drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh));
874 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619

◆ drawPixmap() [4/11]

void QPainter::drawPixmap ( int  x,
int  y,
const QPixmap pixmap,
int  sx,
int  sy,
int  sw,
int  sh 
)
inline

Draws a pixmap at ({x}, {y}) by copying a part of the given pixmap into the paint device.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

({x}, {y}) specifies the top-left point in the paint device that is to be drawn onto. ({sx}, {sy}) specifies the top-left point in pixmap that is to be drawn. The default is (0, 0).

({sw}, {sh}) specifies the size of the pixmap that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the pixmap.

Definition at line 876 of file qpainter.h.

878 {
879  drawPixmap(QRectF(x, y, -1, -1), pm, QRectF(sx, sy, sw, sh));
880 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619

◆ drawPixmap() [5/11]

void QPainter::drawPixmap ( const QPointF point,
const QPixmap pixmap,
const QRectF source 
)
inline

Draws the rectangular portion source of the given pixmap with its origin at the given point.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 882 of file qpainter.h.

883 {
884  drawPixmap(QRectF(p.x(), p.y(), -1, -1), pm, sr);
885 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619

◆ drawPixmap() [6/11]

void QPainter::drawPixmap ( const QPoint point,
const QPixmap pixmap,
const QRect source 
)
inline

Draws the rectangular portion source of the given pixmap with its origin at the given point.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 887 of file qpainter.h.

888 {
889  drawPixmap(QRectF(p.x(), p.y(), -1, -1), pm, sr);
890 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619

◆ drawPixmap() [7/11]

void QPainter::drawPixmap ( const QPointF point,
const QPixmap pixmap 
)

Draws the given pixmap with its origin at the given point.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 5548 of file qpainter.cpp.

5549 {
5550 #if defined QT_DEBUG_DRAW
5551  if (qt_show_painter_debug_output)
5552  printf("QPainter::drawPixmap(), p=[%.2f,%.2f], pix=[%d,%d]\n",
5553  p.x(), p.y(),
5554  pm.width(), pm.height());
5555 #endif
5556 
5557  Q_D(QPainter);
5558 
5559  if (!d->engine || pm.isNull())
5560  return;
5561 
5562 #ifndef QT_NO_DEBUG
5563  qt_painter_thread_test(d->device->devType(), "drawPixmap()", true);
5564 #endif
5565 
5566  if (d->extended) {
5567  d->extended->drawPixmap(p, pm);
5568  return;
5569  }
5570 
5571  qreal x = p.x();
5572  qreal y = p.y();
5573 
5574  int w = pm.width();
5575  int h = pm.height();
5576 
5577  if (w <= 0)
5578  return;
5579 
5580  // Emulate opaque background for bitmaps
5581  if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) {
5582  fillRect(QRectF(x, y, w, h), d->state->bgBrush.color());
5583  }
5584 
5585  d->updateState(d->state);
5586 
5587  if ((d->state->matrix.type() > QTransform::TxTranslate
5588  && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
5589  || (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
5590  || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
5591  {
5592  save();
5593  // If there is no rotation involved we have to make sure we use the
5594  // antialiased and not the aliased coordinate system by rounding the coordinates.
5595  if (d->state->matrix.type() <= QTransform::TxScale) {
5596  const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
5597  x = p.x();
5598  y = p.y();
5599  }
5600  translate(x, y);
5603  QBrush brush(d->state->pen.color(), pm);
5604  setBrush(brush);
5605  setPen(Qt::NoPen);
5606  setBrushOrigin(QPointF(0, 0));
5607 
5608  drawRect(pm.rect());
5609  restore();
5610  } else {
5611  if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
5612  x += d->state->matrix.dx();
5613  y += d->state->matrix.dy();
5614  }
5615  d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(0, 0, w, h));
5616  }
5617 }
void setBackgroundMode(Qt::BGMode mode)
Sets the background mode of the painter to the given mode.
Definition: qpainter.cpp:3998
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
#define Q_D(Class)
Definition: qglobal.h:2482
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QPointF roundInDeviceCoordinates(const QPointF &p, const QTransform &m)
Definition: qpainter.cpp:5518
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
static bool qt_painter_thread_test(int devType, const char *what, bool extraCondition=false)
Definition: qpainter.cpp:156
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ drawPixmap() [8/11]

void QPainter::drawPixmap ( const QPoint point,
const QPixmap pixmap 
)
inline

Draws the given pixmap with its origin at the given point.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 850 of file qpainter.h.

851 {
852  drawPixmap(QPointF(p), pm);
853 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619

◆ drawPixmap() [9/11]

void QPainter::drawPixmap ( int  x,
int  y,
const QPixmap pixmap 
)
inline

Draws the given pixmap at position ({x}, {y}).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 860 of file qpainter.h.

861 {
862  drawPixmap(QPointF(x, y), pm);
863 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619

◆ drawPixmap() [10/11]

void QPainter::drawPixmap ( const QRect rectangle,
const QPixmap pixmap 
)
inline

Draws the given pixmap into the given rectangle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note
The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.

Definition at line 855 of file qpainter.h.

856 {
857  drawPixmap(QRectF(r), pm, QRectF());
858 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619

◆ drawPixmap() [11/11]

void QPainter::drawPixmap ( int  x,
int  y,
int  width,
int  height,
const QPixmap pixmap 
)
inline

Draws the pixmap into the rectangle at position ({x}, {y}) with the given width and height.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 865 of file qpainter.h.

866 {
867  drawPixmap(QRectF(x, y, w, h), pm, QRectF());
868 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619

◆ drawPixmapFragments() [1/2]

void QPainter::drawPixmapFragments ( const PixmapFragment fragments,
int  fragmentCount,
const QPixmap pixmap,
PixmapFragmentHints  hints = 0 
)

This function is used to draw pixmap, or a sub-rectangle of pixmap, at multiple positions with different scale, rotation and opacity.

Since
4.7

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 function is potentially faster than multiple calls to drawPixmap(), since the backend can optimize state changes.

See also
QPainter::PixmapFragment, QPainter::PixmapFragmentHint

Definition at line 9697 of file qpainter.cpp.

Referenced by QDeclarativeParticlesPainter::paint(), and qDrawBorderPixmap().

9699 {
9700  Q_D(QPainter);
9701 
9702  if (!d->engine || pixmap.isNull())
9703  return;
9704 
9705 #ifndef QT_NO_DEBUG
9706  for (int i = 0; i < fragmentCount; ++i) {
9707  QRectF sourceRect(fragments[i].sourceLeft, fragments[i].sourceTop,
9708  fragments[i].width, fragments[i].height);
9709  if (!(QRectF(pixmap.rect()).contains(sourceRect)))
9710  qWarning("QPainter::drawPixmapFragments - the source rect is not contained by the pixmap's rectangle");
9711  }
9712 #endif
9713 
9714  if (d->engine->isExtended()) {
9715  d->extended->drawPixmapFragments(fragments, fragmentCount, pixmap, hints);
9716  } else {
9717  qreal oldOpacity = opacity();
9718  QTransform oldTransform = transform();
9719 
9720  for (int i = 0; i < fragmentCount; ++i) {
9721  QTransform transform = oldTransform;
9722  qreal xOffset = 0;
9723  qreal yOffset = 0;
9724  if (fragments[i].rotation == 0) {
9725  xOffset = fragments[i].x;
9726  yOffset = fragments[i].y;
9727  } else {
9728  transform.translate(fragments[i].x, fragments[i].y);
9729  transform.rotate(fragments[i].rotation);
9730  }
9731  setOpacity(oldOpacity * fragments[i].opacity);
9732  setTransform(transform);
9733 
9734  qreal w = fragments[i].scaleX * fragments[i].width;
9735  qreal h = fragments[i].scaleY * fragments[i].height;
9736  QRectF sourceRect(fragments[i].sourceLeft, fragments[i].sourceTop,
9737  fragments[i].width, fragments[i].height);
9738  drawPixmap(QRectF(qreal(-0.5) * w + xOffset, qreal(-0.5) * h + yOffset, w, h), pixmap, sourceRect);
9739  }
9740 
9741  setOpacity(oldOpacity);
9742  setTransform(oldTransform);
9743  }
9744 }
void setTransform(const QTransform &transform, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9547
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
const QTransform & transform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9558
qreal opacity() const
Returns the opacity of the painter.
Definition: qpainter.cpp:2115
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis)
Rotates the coordinate system counterclockwise by the given angle about the specified axis and return...
Definition: qtransform.cpp:615
Q_CORE_EXPORT void qWarning(const char *,...)
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ drawPixmapFragments() [2/2]

void QPainter::drawPixmapFragments ( const QRectF targetRects,
const QRectF sourceRects,
int  fragmentCount,
const QPixmap pixmap,
PixmapFragmentHints  hints = 0 
)

This function is used to draw the same pixmap with multiple target and source rectangles specified by targetRects.

Since
4.8

If sourceRects is 0, the whole pixmap will be rendered at each of the target rectangles. The hints parameter can be used to pass in drawing hints.

This function is potentially faster than multiple calls to drawPixmap(), since the backend can optimize state changes.

See also
QPainter::PixmapFragmentHint

Definition at line 9763 of file qpainter.cpp.

9765 {
9766  Q_D(QPainter);
9767 
9768  if (!d->engine || pixmap.isNull())
9769  return;
9770 
9771 #ifndef QT_NO_DEBUG
9772  if (sourceRects) {
9773  for (int i = 0; i < fragmentCount; ++i) {
9774  QRectF sourceRect = sourceRects[i];
9775  if (!(QRectF(pixmap.rect()).contains(sourceRect)))
9776  qWarning("QPainter::drawPixmapFragments - the source rect is not contained by the pixmap's rectangle");
9777  }
9778  }
9779 #endif
9780 
9781  if (d->engine->isExtended()) {
9782  d->extended->drawPixmapFragments(targetRects, sourceRects, fragmentCount, pixmap, hints);
9783  } else {
9784  if (sourceRects) {
9785  for (int i = 0; i < fragmentCount; ++i)
9786  drawPixmap(targetRects[i], pixmap, sourceRects[i]);
9787  } else {
9788  QRectF sourceRect = pixmap.rect();
9789  for (int i = 0; i < fragmentCount; ++i)
9790  drawPixmap(targetRects[i], pixmap, sourceRect);
9791  }
9792  }
9793 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
Q_CORE_EXPORT void qWarning(const char *,...)
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ drawPoint() [1/3]

void QPainter::drawPoint ( const QPointF position)
inline

Draws a single point at the given position using the current pen's color.

See also
{Coordinate System}

Definition at line 676 of file qpainter.h.

Referenced by QPlastiqueStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QWindowsCEStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QPicture::exec(), QWhatsThat::paintEvent(), QWizardHeader::paintEvent(), qDrawPlainRect(), and qt_cleanlooks_draw_mdibutton().

677 {
678  drawPoints(&p, 1);
679 }
void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the array points using the current pen&#39;s color.
Definition: qpainter.cpp:3816

◆ drawPoint() [2/3]

void QPainter::drawPoint ( const QPoint position)
inline

Draws a single point at the given position using the current pen's color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 687 of file qpainter.h.

688 {
689  drawPoints(&p, 1);
690 }
void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the array points using the current pen&#39;s color.
Definition: qpainter.cpp:3816

◆ drawPoint() [3/3]

void QPainter::drawPoint ( int  x,
int  y 
)
inline

Draws a single point at position (x, y).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 681 of file qpainter.h.

682 {
683  QPoint p(x, y);
684  drawPoints(&p, 1);
685 }
void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the array points using the current pen&#39;s color.
Definition: qpainter.cpp:3816
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ drawPoints() [1/4]

void QPainter::drawPoints ( const QPointF points,
int  pointCount 
)

Draws the first pointCount points in the array points using the current pen's color.

See also
{Coordinate System}

Definition at line 3816 of file qpainter.cpp.

Referenced by QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QPainterReplayer::process(), qt_cleanlooks_draw_mdibutton(), qt_plastique_draw_frame(), qt_plastique_draw_mdibutton(), and qt_plastique_drawFrame().

3817 {
3818 #ifdef QT_DEBUG_DRAW
3819  if (qt_show_painter_debug_output)
3820  printf("QPainter::drawPoints(), count=%d\n", pointCount);
3821 #endif
3822  Q_D(QPainter);
3823 
3824  if (!d->engine) {
3825  qWarning("QPainter::drawPoints: Painter not active");
3826  return;
3827  }
3828 
3829  if (pointCount <= 0)
3830  return;
3831 
3832  if (d->extended) {
3833  d->extended->drawPoints(points, pointCount);
3834  return;
3835  }
3836 
3837  d->updateState(d->state);
3838 
3839  if (!d->state->emulationSpecifier) {
3840  d->engine->drawPoints(points, pointCount);
3841  return;
3842  }
3843 
3844  if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
3845  && d->state->matrix.type() == QTransform::TxTranslate) {
3846  // ### use drawPoints function
3847  for (int i=0; i<pointCount; ++i) {
3848  QPointF pt(points[i].x() + d->state->matrix.dx(),
3849  points[i].y() + d->state->matrix.dy());
3850  d->engine->drawPoints(&pt, 1);
3851  }
3852  } else {
3853  QPen pen = d->state->pen;
3854  bool flat_pen = pen.capStyle() == Qt::FlatCap;
3855  if (flat_pen) {
3856  save();
3858  setPen(pen);
3859  }
3860  QPainterPath path;
3861  for (int i=0; i<pointCount; ++i) {
3862  path.moveTo(points[i].x(), points[i].y());
3863  path.lineTo(points[i].x() + 0.0001, points[i].y());
3864  }
3865  d->draw_helper(path, QPainterPrivate::StrokeDraw);
3866  if (flat_pen)
3867  restore();
3868  }
3869 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void setCapStyle(Qt::PenCapStyle pcs)
Sets the pen&#39;s cap style to the given style.
Definition: qpen.cpp:723
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
Q_CORE_EXPORT void qWarning(const char *,...)
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
Qt::PenCapStyle capStyle() const
Returns the pen&#39;s cap style.
Definition: qpen.cpp:706

◆ drawPoints() [2/4]

void QPainter::drawPoints ( const QPolygonF points)
inline

Draws the points in the vector points.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 692 of file qpainter.h.

693 {
694  drawPoints(points.constData(), points.size());
695 }
void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the array points using the current pen&#39;s color.
Definition: qpainter.cpp:3816
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ drawPoints() [3/4]

void QPainter::drawPoints ( const QPoint points,
int  pointCount 
)

Draws the first pointCount points in the array points using the current pen's color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 3881 of file qpainter.cpp.

3882 {
3883 #ifdef QT_DEBUG_DRAW
3884  if (qt_show_painter_debug_output)
3885  printf("QPainter::drawPoints(), count=%d\n", pointCount);
3886 #endif
3887  Q_D(QPainter);
3888 
3889  if (!d->engine) {
3890  qWarning("QPainter::drawPoints: Painter not active");
3891  return;
3892  }
3893 
3894  if (pointCount <= 0)
3895  return;
3896 
3897  if (d->extended) {
3898  d->extended->drawPoints(points, pointCount);
3899  return;
3900  }
3901 
3902  d->updateState(d->state);
3903 
3904  if (!d->state->emulationSpecifier) {
3905  d->engine->drawPoints(points, pointCount);
3906  return;
3907  }
3908 
3909  if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
3910  && d->state->matrix.type() == QTransform::TxTranslate) {
3911  // ### use drawPoints function
3912  for (int i=0; i<pointCount; ++i) {
3913  QPointF pt(points[i].x() + d->state->matrix.dx(),
3914  points[i].y() + d->state->matrix.dy());
3915  d->engine->drawPoints(&pt, 1);
3916  }
3917  } else {
3918  QPen pen = d->state->pen;
3919  bool flat_pen = (pen.capStyle() == Qt::FlatCap);
3920  if (flat_pen) {
3921  save();
3923  setPen(pen);
3924  }
3925  QPainterPath path;
3926  for (int i=0; i<pointCount; ++i) {
3927  path.moveTo(points[i].x(), points[i].y());
3928  path.lineTo(points[i].x() + 0.0001, points[i].y());
3929  }
3930  d->draw_helper(path, QPainterPrivate::StrokeDraw);
3931  if (flat_pen)
3932  restore();
3933  }
3934 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void setCapStyle(Qt::PenCapStyle pcs)
Sets the pen&#39;s cap style to the given style.
Definition: qpen.cpp:723
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
Q_CORE_EXPORT void qWarning(const char *,...)
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
Qt::PenCapStyle capStyle() const
Returns the pen&#39;s cap style.
Definition: qpen.cpp:706

◆ drawPoints() [4/4]

void QPainter::drawPoints ( const QPolygon points)
inline

Draws the points in the vector points.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 697 of file qpainter.h.

698 {
699  drawPoints(points.constData(), points.size());
700 }
void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the array points using the current pen&#39;s color.
Definition: qpainter.cpp:3816
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ drawPolygon() [1/4]

void QPainter::drawPolygon ( const QPointF points,
int  pointCount,
Qt::FillRule  fillRule = Qt::OddEvenFill 
)

Draws the polygon defined by the first pointCount points in the array points using the current pen and brush.

qpainter-polygon.png
static const QPointF points[4] = {
QPointF(10.0, 80.0),
QPointF(20.0, 10.0),
QPointF(80.0, 30.0),
QPointF(90.0, 70.0)
};
QPainter painter(this);
painter.drawPolygon(points, 4);

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. See Qt::FillRule for a more detailed description of these fill rules.

See also
drawConvexPolygon(), drawPolyline(), {Coordinate System}

Definition at line 5205 of file qpainter.cpp.

Referenced by QSvgPolygon::draw(), QSvgPolyline::draw(), QCommonStyle::drawComplexControl(), QWindowsCEStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QCommonStyle::drawControl(), QMotifStyle::drawControl(), QCommonStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QLCDNumberPrivate::drawSegment(), QPicture::exec(), QX11PaintEnginePrivate::fillPolygon_dev(), QGraphicsPolygonItem::paint(), QColorLuminancePicker::paintEvent(), QPainterReplayer::process(), and qDrawPlainRect().

5206 {
5207 #ifdef QT_DEBUG_DRAW
5208  if (qt_show_painter_debug_output)
5209  printf("QPainter::drawPolygon(), count=%d\n", pointCount);
5210 #endif
5211 
5212  Q_D(QPainter);
5213 
5214  if (!d->engine || pointCount < 2)
5215  return;
5216 
5217  if (d->extended) {
5218  d->extended->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule));
5219  return;
5220  }
5221 
5222  d->updateState(d->state);
5223 
5224  uint emulationSpecifier = d->state->emulationSpecifier;
5225 
5226  if (emulationSpecifier) {
5227  QPainterPath polygonPath(points[0]);
5228  for (int i=1; i<pointCount; ++i)
5229  polygonPath.lineTo(points[i]);
5230  polygonPath.closeSubpath();
5231  polygonPath.setFillRule(fillRule);
5232  d->draw_helper(polygonPath);
5233  return;
5234  }
5235 
5236  d->engine->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule));
5237 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
unsigned int uint
Definition: qglobal.h:996

◆ drawPolygon() [2/4]

void QPainter::drawPolygon ( const QPolygonF points,
Qt::FillRule  fillRule = Qt::OddEvenFill 
)
inline

Draws the polygon defined by the given points using the fill rule fillRule.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 630 of file qpainter.h.

631 {
632  drawPolygon(polygon.constData(), polygon.size(), fillRule);
633 }
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
Draws the polygon defined by the first pointCount points in the array points using the current pen an...
Definition: qpainter.cpp:5205

◆ drawPolygon() [3/4]

void QPainter::drawPolygon ( const QPoint points,
int  pointCount,
Qt::FillRule  fillRule = Qt::OddEvenFill 
)

Draws the polygon defined by the first pointCount points in the array points.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 5247 of file qpainter.cpp.

5248 {
5249 #ifdef QT_DEBUG_DRAW
5250  if (qt_show_painter_debug_output)
5251  printf("QPainter::drawPolygon(), count=%d\n", pointCount);
5252 #endif
5253 
5254  Q_D(QPainter);
5255 
5256  if (!d->engine || pointCount < 2)
5257  return;
5258 
5259  if (d->extended) {
5260  d->extended->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule));
5261  return;
5262  }
5263 
5264  d->updateState(d->state);
5265 
5266  uint emulationSpecifier = d->state->emulationSpecifier;
5267 
5268  if (emulationSpecifier) {
5269  QPainterPath polygonPath(points[0]);
5270  for (int i=1; i<pointCount; ++i)
5271  polygonPath.lineTo(points[i]);
5272  polygonPath.closeSubpath();
5273  polygonPath.setFillRule(fillRule);
5274  d->draw_helper(polygonPath);
5275  return;
5276  }
5277 
5278  d->engine->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule));
5279 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
unsigned int uint
Definition: qglobal.h:996

◆ drawPolygon() [4/4]

void QPainter::drawPolygon ( const QPolygon points,
Qt::FillRule  fillRule = Qt::OddEvenFill 
)
inline

Draws the polygon defined by the given points using the fill rule fillRule.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 635 of file qpainter.h.

636 {
637  drawPolygon(polygon.constData(), polygon.size(), fillRule);
638 }
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
Draws the polygon defined by the first pointCount points in the array points using the current pen an...
Definition: qpainter.cpp:5205

◆ drawPolyline() [1/4]

void QPainter::drawPolyline ( const QPointF points,
int  pointCount 
)

Draws the polyline defined by the first pointCount points in points using the current pen.

Note that unlike the drawPolygon() function the last point is not connected to the first, neither is the polyline filled.

static const QPointF points[3] = {
QPointF(10.0, 80.0),
QPointF(20.0, 10.0),
QPointF(80.0, 30.0),
};
QPainter painter(this);
painter.drawPolyline(points, 3);
See also
drawLines(), drawPolygon(), {Coordinate System}

Definition at line 5055 of file qpainter.cpp.

Referenced by QSvgPolyline::draw(), QCommonStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QWindowsCEStylePrivate::drawWinCEShades(), QWindowsCEStylePrivate::drawWinCEShadesSunken(), QWindowsCEStylePrivate::drawWinShades(), QPicture::exec(), QPainterReplayer::process(), qDrawShadeLine(), and qDrawWinShades().

5056 {
5057 #ifdef QT_DEBUG_DRAW
5058  if (qt_show_painter_debug_output)
5059  printf("QPainter::drawPolyline(), count=%d\n", pointCount);
5060 #endif
5061  Q_D(QPainter);
5062 
5063  if (!d->engine || pointCount < 2)
5064  return;
5065 
5066  if (d->extended) {
5067  d->extended->drawPolygon(points, pointCount, QPaintEngine::PolylineMode);
5068  return;
5069  }
5070 
5071  d->updateState(d->state);
5072 
5073  uint lineEmulation = line_emulation(d->state->emulationSpecifier);
5074 
5075  if (lineEmulation) {
5076  // ###
5077 // if (lineEmulation == QPaintEngine::PrimitiveTransform
5078 // && d->state->matrix.type() == QTransform::TxTranslate) {
5079 // } else {
5080  QPainterPath polylinePath(points[0]);
5081  for (int i=1; i<pointCount; ++i)
5082  polylinePath.lineTo(points[i]);
5083  d->draw_helper(polylinePath, QPainterPrivate::StrokeDraw);
5084 // }
5085  } else {
5086  d->engine->drawPolygon(points, pointCount, QPaintEngine::PolylineMode);
5087  }
5088 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
static uint line_emulation(uint emulation)
Definition: qpainter.cpp:143
unsigned int uint
Definition: qglobal.h:996

◆ drawPolyline() [2/4]

void QPainter::drawPolyline ( const QPolygonF points)
inline

Draws the polyline defined by the given points using the current pen.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 620 of file qpainter.h.

621 {
622  drawPolyline(polyline.constData(), polyline.size());
623 }
void drawPolyline(const QPointF *points, int pointCount)
Draws the polyline defined by the first pointCount points in points using the current pen...
Definition: qpainter.cpp:5055

◆ drawPolyline() [3/4]

void QPainter::drawPolyline ( const QPoint points,
int  pointCount 
)

Draws the polyline defined by the first pointCount points in points using the current pen.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 5099 of file qpainter.cpp.

5100 {
5101 #ifdef QT_DEBUG_DRAW
5102  if (qt_show_painter_debug_output)
5103  printf("QPainter::drawPolyline(), count=%d\n", pointCount);
5104 #endif
5105  Q_D(QPainter);
5106 
5107  if (!d->engine || pointCount < 2)
5108  return;
5109 
5110  if (d->extended) {
5111  d->extended->drawPolygon(points, pointCount, QPaintEngine::PolylineMode);
5112  return;
5113  }
5114 
5115  d->updateState(d->state);
5116 
5117  uint lineEmulation = line_emulation(d->state->emulationSpecifier);
5118 
5119  if (lineEmulation) {
5120  // ###
5121 // if (lineEmulation == QPaintEngine::PrimitiveTransform
5122 // && d->state->matrix.type() == QTransform::TxTranslate) {
5123 // } else {
5124  QPainterPath polylinePath(points[0]);
5125  for (int i=1; i<pointCount; ++i)
5126  polylinePath.lineTo(points[i]);
5127  d->draw_helper(polylinePath, QPainterPrivate::StrokeDraw);
5128 // }
5129  } else {
5130  d->engine->drawPolygon(points, pointCount, QPaintEngine::PolylineMode);
5131  }
5132 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
static uint line_emulation(uint emulation)
Definition: qpainter.cpp:143
unsigned int uint
Definition: qglobal.h:996

◆ drawPolyline() [4/4]

void QPainter::drawPolyline ( const QPolygon points)
inline

Draws the polyline defined by the given points using the current pen.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 625 of file qpainter.h.

626 {
627  drawPolyline(polyline.constData(), polyline.size());
628 }
void drawPolyline(const QPointF *points, int pointCount)
Draws the polyline defined by the first pointCount points in points using the current pen...
Definition: qpainter.cpp:5055

◆ drawRect() [1/3]

void QPainter::drawRect ( const QRectF rectangle)
inline

Draws the current rectangle with the current pen and brush.

A filled rectangle has a size of {rectangle}.size(). A stroked rectangle has a size of {rectangle}.size() plus the pen width.

qpainter-rectangle.png
QRectF rectangle(10.0, 20.0, 80.0, 60.0);
QPainter painter(this);
painter.drawRect(rectangle);
See also
drawRects(), drawPolygon(), {Coordinate System}

Definition at line 650 of file qpainter.h.

Referenced by QFontEngineBox::boundingBox(), QmlJSDebugger::ToolBarColorBox::createDragPixmap(), QSvgRect::draw(), QGraphicsScenePrivate::draw(), QTextDocumentLayoutPrivate::drawBorder(), QPaintEnginePrivate::drawBoxTextItem(), QWindowsCEStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QItemDelegate::drawDisplay(), drawImage(), drawPixmap(), QPaintEngine::drawPoints(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QDeclarativeRectangle::drawRect(), drawRoundedRect(), QWindowsMobileStylePrivate::drawScrollbarGrip(), drawTiledPixmap(), QPicture::exec(), fillRect(), QDeclarativeRectangle::generateBorderedRect(), QColorWell::mouseMoveEvent(), QColorShowLabel::mouseMoveEvent(), QFontFamilyDelegate::paint(), QGraphicsRectItem::paint(), QGraphicsItemGroup::paint(), QPagePreview::paintEvent(), QWhatsThat::paintEvent(), qDrawEdge(), qDrawPlainRect(), qDrawShadeRect(), and qt_graphicsItem_highlightSelected().

651 {
652  drawRects(&rect, 1);
653 }
void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount of the given rectangles using the current pen and brush.
Definition: qpainter.cpp:3641

◆ drawRect() [2/3]

void QPainter::drawRect ( int  x,
int  y,
int  width,
int  height 
)
inline

Draws a rectangle with upper left corner at ({x}, {y}) and with the given width and height.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 655 of file qpainter.h.

656 {
657  QRect r(x, y, w, h);
658  drawRects(&r, 1);
659 }
void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount of the given rectangles using the current pen and brush.
Definition: qpainter.cpp:3641
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ drawRect() [3/3]

void QPainter::drawRect ( const QRect rectangle)
inline

Draws the current rectangle with the current pen and brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 661 of file qpainter.h.

662 {
663  drawRects(&r, 1);
664 }
void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount of the given rectangles using the current pen and brush.
Definition: qpainter.cpp:3641

◆ drawRects() [1/4]

void QPainter::drawRects ( const QRectF rectangles,
int  rectCount 
)

Draws the first rectCount of the given rectangles using the current pen and brush.

See also
drawRect()

Definition at line 3641 of file qpainter.cpp.

Referenced by QCleanlooksStyle::drawPrimitive(), QPainterReplayer::process(), and QWidgetPrivate::setWindowOpacity_sys().

3642 {
3643 #ifdef QT_DEBUG_DRAW
3644  if (qt_show_painter_debug_output)
3645  printf("QPainter::drawRects(), count=%d\n", rectCount);
3646 #endif
3647  Q_D(QPainter);
3648 
3649  if (!d->engine) {
3650  qWarning("QPainter::drawRects: Painter not active");
3651  return;
3652  }
3653 
3654  if (rectCount <= 0)
3655  return;
3656 
3657  if (d->extended) {
3658  d->extended->drawRects(rects, rectCount);
3659  return;
3660  }
3661 
3662  d->updateState(d->state);
3663 
3664  if (!d->state->emulationSpecifier) {
3665  d->engine->drawRects(rects, rectCount);
3666  return;
3667  }
3668 
3669  if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
3670  && d->state->matrix.type() == QTransform::TxTranslate) {
3671  for (int i=0; i<rectCount; ++i) {
3672  QRectF r(rects[i].x() + d->state->matrix.dx(),
3673  rects[i].y() + d->state->matrix.dy(),
3674  rects[i].width(),
3675  rects[i].height());
3676  d->engine->drawRects(&r, 1);
3677  }
3678  } else {
3679  if (d->state->brushNeedsResolving() || d->state->penNeedsResolving()) {
3680  for (int i=0; i<rectCount; ++i) {
3681  QPainterPath rectPath;
3682  rectPath.addRect(rects[i]);
3683  d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw);
3684  }
3685  } else {
3686  QPainterPath rectPath;
3687  for (int i=0; i<rectCount; ++i)
3688  rectPath.addRect(rects[i]);
3689  d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw);
3690  }
3691  }
3692 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
Q_CORE_EXPORT void qWarning(const char *,...)
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.

◆ drawRects() [2/4]

void QPainter::drawRects ( const QVector< QRectF > &  rectangles)
inline

Draws the given rectangles using the current pen and brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 666 of file qpainter.h.

667 {
668  drawRects(rects.constData(), rects.size());
669 }
void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount of the given rectangles using the current pen and brush.
Definition: qpainter.cpp:3641

◆ drawRects() [3/4]

void QPainter::drawRects ( const QRect rects,
int  rectCount 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the first rectCount of the given rectangles using the current pen and brush.

Definition at line 3701 of file qpainter.cpp.

3702 {
3703 #ifdef QT_DEBUG_DRAW
3704  if (qt_show_painter_debug_output)
3705  printf("QPainter::drawRects(), count=%d\n", rectCount);
3706 #endif
3707  Q_D(QPainter);
3708 
3709  if (!d->engine) {
3710  qWarning("QPainter::drawRects: Painter not active");
3711  return;
3712  }
3713 
3714  if (rectCount <= 0)
3715  return;
3716 
3717  if (d->extended) {
3718  d->extended->drawRects(rects, rectCount);
3719  return;
3720  }
3721 
3722  d->updateState(d->state);
3723 
3724  if (!d->state->emulationSpecifier) {
3725  d->engine->drawRects(rects, rectCount);
3726  return;
3727  }
3728 
3729  if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
3730  && d->state->matrix.type() == QTransform::TxTranslate) {
3731  for (int i=0; i<rectCount; ++i) {
3732  QRectF r(rects[i].x() + d->state->matrix.dx(),
3733  rects[i].y() + d->state->matrix.dy(),
3734  rects[i].width(),
3735  rects[i].height());
3736 
3737  d->engine->drawRects(&r, 1);
3738  }
3739  } else {
3740  if (d->state->brushNeedsResolving() || d->state->penNeedsResolving()) {
3741  for (int i=0; i<rectCount; ++i) {
3742  QPainterPath rectPath;
3743  rectPath.addRect(rects[i]);
3744  d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw);
3745  }
3746  } else {
3747  QPainterPath rectPath;
3748  for (int i=0; i<rectCount; ++i)
3749  rectPath.addRect(rects[i]);
3750 
3751  d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw);
3752  }
3753  }
3754 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
Q_CORE_EXPORT void qWarning(const char *,...)
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255

◆ drawRects() [4/4]

void QPainter::drawRects ( const QVector< QRect > &  rectangles)
inline

Draws the given rectangles using the current pen and brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 671 of file qpainter.h.

672 {
673  drawRects(rects.constData(), rects.size());
674 }
void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount of the given rectangles using the current pen and brush.
Definition: qpainter.cpp:3641

◆ drawRoundedRect() [1/3]

void QPainter::drawRoundedRect ( const QRectF rect,
qreal  xRadius,
qreal  yRadius,
Qt::SizeMode  mode = Qt::AbsoluteSize 
)

Draws the given rectangle rect with rounded corners.

Since
4.4

The xRadius and yRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. When mode is Qt::RelativeSize, 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.

qpainter-roundrect.png
QRectF rectangle(10.0, 20.0, 80.0, 60.0);
QPainter painter(this);
painter.drawRoundedRect(rectangle, 20.0, 15.0);
See also
drawRect(), QPen

Definition at line 4348 of file qpainter.cpp.

Referenced by QSvgRect::draw(), QDeclarativeRectangle::drawRect(), drawRoundRect(), QPicture::exec(), and QDeclarativeRectangle::generateRoundedRect().

4349 {
4350 #ifdef QT_DEBUG_DRAW
4351  if (qt_show_painter_debug_output)
4352  printf("QPainter::drawRoundedRect(), [%.2f,%.2f,%.2f,%.2f]\n", rect.x(), rect.y(), rect.width(), rect.height());
4353 #endif
4354  Q_D(QPainter);
4355 
4356  if (!d->engine)
4357  return;
4358 
4359  if (xRadius <= 0 || yRadius <= 0) { // draw normal rectangle
4360  drawRect(rect);
4361  return;
4362  }
4363 
4364  if (d->extended) {
4365  d->extended->drawRoundedRect(rect, xRadius, yRadius, mode);
4366  return;
4367  }
4368 
4369  QPainterPath path;
4370  path.addRoundedRect(rect, xRadius, yRadius, mode);
4371  drawPath(path);
4372 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Adds the given rectangle rect with rounded corners to the path.
#define Q_D(Class)
Definition: qglobal.h:2482
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650

◆ drawRoundedRect() [2/3]

void QPainter::drawRoundedRect ( int  x,
int  y,
int  w,
int  h,
qreal  xRadius,
qreal  yRadius,
Qt::SizeMode  mode = Qt::AbsoluteSize 
)
inline

Definition at line 712 of file qpainter.h.

714 {
715  drawRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode);
716 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Draws the given rectangle rect with rounded corners.
Definition: qpainter.cpp:4348

◆ drawRoundedRect() [3/3]

void QPainter::drawRoundedRect ( const QRect rect,
qreal  xRadius,
qreal  yRadius,
Qt::SizeMode  mode = Qt::AbsoluteSize 
)
inline

Definition at line 718 of file qpainter.h.

720 {
721  drawRoundedRect(QRectF(rect), xRadius, yRadius, mode);
722 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Draws the given rectangle rect with rounded corners.
Definition: qpainter.cpp:4348

◆ drawRoundRect() [1/3]

void QPainter::drawRoundRect ( const QRectF r,
int  xRnd = 25,
int  yRnd = 25 
)

Draws a rectangle r with rounded corners.

The xRnd and yRnd arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.

A filled rectangle has a size of r.size(). A stroked rectangle has a size of r.size() plus the pen width.

See also
drawRoundedRect()

Definition at line 4414 of file qpainter.cpp.

4415 {
4416  drawRoundedRect(r, xRnd, yRnd, Qt::RelativeSize);
4417 }
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Draws the given rectangle rect with rounded corners.
Definition: qpainter.cpp:4348

◆ drawRoundRect() [2/3]

void QPainter::drawRoundRect ( int  x,
int  y,
int  w,
int  h,
int  xRnd = 25,
int  yRnd = 25 
)
inline

Draws the rectangle x, y, w, h with rounded corners.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 702 of file qpainter.h.

703 {
704  drawRoundRect(QRectF(x, y, w, h), xRnd, yRnd);
705 }
void drawRoundRect(const QRectF &r, int xround=25, int yround=25)
Draws a rectangle r with rounded corners.
Definition: qpainter.cpp:4414
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ drawRoundRect() [3/3]

void QPainter::drawRoundRect ( const QRect r,
int  xRnd = 25,
int  yRnd = 25 
)
inline

Draws the rectangle r with rounded corners.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 707 of file qpainter.h.

708 {
709  drawRoundRect(QRectF(rect), xRnd, yRnd);
710 }
void drawRoundRect(const QRectF &r, int xround=25, int yround=25)
Draws a rectangle r with rounded corners.
Definition: qpainter.cpp:4414
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ drawStaticText() [1/3]

void QPainter::drawStaticText ( const QPointF topLeftPosition,
const QStaticText staticText 
)

Draws the given staticText at the given topLeftPosition.

Since
4.7

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.

Note
If the painter's transformation is not affine, then staticText will be drawn using regular calls to drawText(), losing any potential for performance improvement.
The y-position is used as the top of the font.
See also
QStaticText

Definition at line 6260 of file qpainter.cpp.

6261 {
6262  Q_D(QPainter);
6263  if (!d->engine || staticText.text().isEmpty() || pen().style() == Qt::NoPen)
6264  return;
6265 
6266  QStaticTextPrivate *staticText_d =
6267  const_cast<QStaticTextPrivate *>(QStaticTextPrivate::get(&staticText));
6268 
6269  if (font() != staticText_d->font) {
6270  staticText_d->font = font();
6271  staticText_d->needsRelayout = true;
6272  }
6273 
6274  // If we don't have an extended paint engine, or if the painter is projected,
6275  // we go through standard code path
6276  if (d->extended == 0 || !d->state->matrix.isAffine()) {
6277  staticText_d->paintText(topLeftPosition, this);
6278  return;
6279  }
6280 
6281  bool supportsTransformations = d->extended->supportsTransformations(staticText_d->font.pixelSize(),
6282  d->state->matrix);
6283  if (supportsTransformations && !staticText_d->untransformedCoordinates) {
6284  staticText_d->untransformedCoordinates = true;
6285  staticText_d->needsRelayout = true;
6286  } else if (!supportsTransformations && staticText_d->untransformedCoordinates) {
6287  staticText_d->untransformedCoordinates = false;
6288  staticText_d->needsRelayout = true;
6289  }
6290 
6291  // Don't recalculate entire layout because of translation, rather add the dx and dy
6292  // into the position to move each text item the correct distance.
6293  QPointF transformedPosition = topLeftPosition;
6294  if (!staticText_d->untransformedCoordinates)
6295  transformedPosition = transformedPosition * d->state->matrix;
6296  QTransform oldMatrix;
6297 
6298  // The translation has been applied to transformedPosition. Remove translation
6299  // component from matrix.
6300  if (d->state->matrix.isTranslating() && !staticText_d->untransformedCoordinates) {
6301  qreal m11 = d->state->matrix.m11();
6302  qreal m12 = d->state->matrix.m12();
6303  qreal m13 = d->state->matrix.m13();
6304  qreal m21 = d->state->matrix.m21();
6305  qreal m22 = d->state->matrix.m22();
6306  qreal m23 = d->state->matrix.m23();
6307  qreal m33 = d->state->matrix.m33();
6308 
6309  oldMatrix = d->state->matrix;
6310  d->state->matrix.setMatrix(m11, m12, m13,
6311  m21, m22, m23,
6312  0.0, 0.0, m33);
6313  }
6314 
6315  // If the transform is not identical to the text transform,
6316  // we have to relayout the text (for other transformations than plain translation)
6317  bool staticTextNeedsReinit = staticText_d->needsRelayout;
6318  if (!staticText_d->untransformedCoordinates && staticText_d->matrix != d->state->matrix) {
6319  staticText_d->matrix = d->state->matrix;
6320  staticTextNeedsReinit = true;
6321  }
6322 
6323  // Recreate the layout of the static text because the matrix or font has changed
6324  if (staticTextNeedsReinit)
6325  staticText_d->init();
6326 
6327  if (transformedPosition != staticText_d->position) { // Translate to actual position
6328  QFixed fx = QFixed::fromReal(transformedPosition.x());
6329  QFixed fy = QFixed::fromReal(transformedPosition.y());
6330  QFixed oldX = QFixed::fromReal(staticText_d->position.x());
6331  QFixed oldY = QFixed::fromReal(staticText_d->position.y());
6332  for (int item=0; item<staticText_d->itemCount;++item) {
6333  QStaticTextItem *textItem = staticText_d->items + item;
6334  for (int i=0; i<textItem->numGlyphs; ++i) {
6335  textItem->glyphPositions[i].x += fx - oldX;
6336  textItem->glyphPositions[i].y += fy - oldY;
6337  }
6338  textItem->userDataNeedsUpdate = true;
6339  }
6340 
6341  staticText_d->position = transformedPosition;
6342  }
6343 
6344  QPen oldPen = d->state->pen;
6345  QColor currentColor = oldPen.color();
6346  for (int i=0; i<staticText_d->itemCount; ++i) {
6347  QStaticTextItem *item = staticText_d->items + i;
6348  if (item->color.isValid() && currentColor != item->color) {
6349  setPen(item->color);
6350  currentColor = item->color;
6351  }
6352  d->extended->drawStaticTextItem(item);
6353 
6355  item->numGlyphs, item->fontEngine(), staticText_d->font,
6356  QTextCharFormat());
6357  }
6358  if (currentColor != oldPen.color())
6359  setPen(oldPen);
6360 
6361  if (!staticText_d->untransformedCoordinates && oldMatrix.isTranslating())
6362  d->state->matrix = oldMatrix;
6363 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
QFontEngine * fontEngine() const
QFixedPoint * glyphPositions
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
int pixelSize() const
Returns the pixel size of the font if it was set with setPixelSize().
Definition: qfont.cpp:1178
unsigned char untransformedCoordinates
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QStaticTextItem * items
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QStaticTextPrivate * get(const QStaticText *q)
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
QFixed y
Definition: qfixed_p.h:191
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const QFont & font() const
Returns the currently set font used for drawing text.
Definition: qpainter.cpp:4312
Q_GUI_EXPORT void qt_draw_decoration_for_glyphs(QPainter *painter, const glyph_t *glyphArray, const QFixedPoint *positions, int glyphCount, QFontEngine *fontEngine, const QFont &font, const QTextCharFormat &charFormat)
Definition: qpainter.cpp:6820
bool isTranslating() const
Returns true if the matrix represents a translating transformation, otherwise returns false...
Definition: qtransform.h:223
QFixed x
Definition: qfixed_p.h:190
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
unsigned char needsRelayout
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
QString text() const
Returns the text of the QStaticText.
void paintText(const QPointF &pos, QPainter *p)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
glyph_t * glyphs

◆ drawStaticText() [2/3]

void QPainter::drawStaticText ( const QPoint topLeftPosition,
const QStaticText staticText 
)
inline

Draws the staticText at the topLeftPosition.

Since
4.7 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Note
The y-position is used as the top of the font.

Definition at line 940 of file qpainter.h.

941 {
942  drawStaticText(QPointF(p), staticText);
943 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawStaticText(const QPointF &topLeftPosition, const QStaticText &staticText)
Draws the given staticText at the given topLeftPosition.
Definition: qpainter.cpp:6260

◆ drawStaticText() [3/3]

void QPainter::drawStaticText ( int  left,
int  top,
const QStaticText staticText 
)
inline

Draws the staticText at coordinates left and top.

Since
4.7 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Note
The y-position is used as the top of the font.

Definition at line 945 of file qpainter.h.

946 {
947  drawStaticText(QPointF(x, y), staticText);
948 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawStaticText(const QPointF &topLeftPosition, const QStaticText &staticText)
Draws the given staticText at the given topLeftPosition.
Definition: qpainter.cpp:6260

◆ drawText() [1/8]

void QPainter::drawText ( const QPointF position,
const QString text 
)

Draws the given text with the currently defined text direction, beginning at the given position.

This function does not handle the newline character (
), as it cannot break text into multiple lines, and it cannot 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.

Note
The y-position is used as the baseline of the font.

Definition at line 6231 of file qpainter.cpp.

Referenced by boundingRect(), QDragManager::drag(), QTextLine::draw(), QCommonStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QStyleSheetStyle::drawComplexControl(), QSplashScreen::drawContents(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QWindowsCEStyle::drawItemText(), QCleanlooksStyle::drawItemText(), QStyle::drawItemText(), QDeclarativeTextPrivate::drawTextLayout(), QVistaHelper::drawTitleText(), QPicture::exec(), QScriptEdit::extraAreaPaintEvent(), QDecorationWindows::paint(), QDecorationDefault::paint(), QFontFamilyDelegate::paint(), QStatusBar::paintEvent(), QPagePreview::paintEvent(), QWhatsThat::paintEvent(), QLineEdit::paintEvent(), printPage(), QPainterReplayer::process(), qDrawPlainRect(), qt_mac_read_fontsmoothing_settings(), QWidget::update(), and QCommonStylePrivate::viewItemDrawText().

6232 {
6233  drawText(p, str, 0, 0);
6234 }
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231

◆ drawText() [2/8]

void QPainter::drawText ( const QPoint position,
const QString text 
)
inline

Draws the given text with the currently defined text direction, beginning at the given position.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

By default, QPainter draws text anti-aliased.

Note
The y-position is used as the baseline of the font.

Definition at line 955 of file qpainter.h.

956 {
957  drawText(QPointF(p), s);
958 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231

◆ drawText() [3/8]

void QPainter::drawText ( int  x,
int  y,
const QString text 
)
inline

Draws the given text at position ({x}, {y}), using the painter's currently defined text direction.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

By default, QPainter draws text anti-aliased.

Note
The y-position is used as the baseline of the font.

Definition at line 965 of file qpainter.h.

966 {
967  drawText(QPointF(x, y), s);
968 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231

◆ drawText() [4/8]

void QPainter::drawText ( const QPointF p,
const QString str,
int  tf,
int  justificationPadding 
)
Warning
This function is not part of the public interface.

Definition at line 6368 of file qpainter.cpp.

6369 {
6370 #ifdef QT_DEBUG_DRAW
6371  if (qt_show_painter_debug_output)
6372  printf("QPainter::drawText(), pos=[%.2f,%.2f], str='%s'\n", p.x(), p.y(), str.toLatin1().constData());
6373 #endif
6374 
6375  Q_D(QPainter);
6376 
6377  if (!d->engine || str.isEmpty() || pen().style() == Qt::NoPen)
6378  return;
6379 
6380  if (tf & Qt::TextBypassShaping) {
6381  // Skip harfbuzz complex shaping, shape using glyph advances only
6382  int len = str.length();
6383  int numGlyphs = len;
6384  QVarLengthGlyphLayoutArray glyphs(len);
6385  QFontEngine *fontEngine = d->state->font.d->engineForScript(QUnicodeTables::Common);
6386  if (!fontEngine->stringToCMap(str.data(), len, &glyphs, &numGlyphs, 0)) {
6387  glyphs.resize(numGlyphs);
6388  if (!fontEngine->stringToCMap(str.data(), len, &glyphs, &numGlyphs, 0))
6389  Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice");
6390  }
6391 
6392  QTextItemInt gf(glyphs, &d->state->font, str.data(), len, fontEngine);
6393  drawTextItem(p, gf);
6394  return;
6395  }
6396 
6397  QStackTextEngine engine(str, d->state->font);
6398  engine.option.setTextDirection(d->state->layoutDirection);
6400  engine.ignoreBidi = true;
6401  engine.option.setTextDirection((tf & Qt::TextForceLeftToRight) ? Qt::LeftToRight : Qt::RightToLeft);
6402  }
6403  engine.itemize();
6404  QScriptLine line;
6405  line.length = str.length();
6406  engine.shapeLine(line);
6407 
6408  int nItems = engine.layoutData->items.size();
6409  QVarLengthArray<int> visualOrder(nItems);
6410  QVarLengthArray<uchar> levels(nItems);
6411  for (int i = 0; i < nItems; ++i)
6412  levels[i] = engine.layoutData->items[i].analysis.bidiLevel;
6413  QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data());
6414 
6415  if (justificationPadding > 0) {
6416  engine.option.setAlignment(Qt::AlignJustify);
6417  engine.forceJustification = true;
6418  // this works because justify() is only interested in the difference between width and textWidth
6419  line.width = justificationPadding;
6420  engine.justify(line);
6421  }
6422  QFixed x = QFixed::fromReal(p.x());
6423 
6424  for (int i = 0; i < nItems; ++i) {
6425  int item = visualOrder[i];
6426  const QScriptItem &si = engine.layoutData->items.at(item);
6428  x += si.width;
6429  continue;
6430  }
6431  QFont f = engine.font(si);
6432  QTextItemInt gf(si, &f);
6433  gf.glyphs = engine.shapedGlyphs(&si);
6434  gf.chars = engine.layoutData->string.unicode() + si.position;
6435  gf.num_chars = engine.length(item);
6436  if (engine.forceJustification) {
6437  for (int j=0; j<gf.glyphs.numGlyphs; ++j)
6438  gf.width += gf.glyphs.effectiveAdvance(j);
6439  } else {
6440  gf.width = si.width;
6441  }
6442  gf.logClusters = engine.logClusters(&si);
6443 
6444  drawTextItem(QPointF(x.toReal(), p.y()), gf);
6445 
6446  x += gf.width;
6447  }
6448 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const =0
#define Q_D(Class)
Definition: qglobal.h:2482
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static void bidiReorder(int numRuns, const quint8 *levels, int *visualOrder)
Internal QTextItem.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
unsigned short flags
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void drawTextItem(const QPointF &p, const QTextItem &ti)
Draws the text item ti at position p.
Definition: qpainter.cpp:6864
qreal toReal() const
Definition: qfixed_p.h:77
signed int length
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QScriptAnalysis analysis
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ drawText() [5/8]

void QPainter::drawText ( const QRectF rectangle,
int  flags,
const QString text,
QRectF boundingRect = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the given text within the provided rectangle.

qpainter-text.png
QPainter painter(this);
painter.drawText(rect, Qt::AlignCenter, tr("Qt by\nNokia"));

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:

See also
Qt::AlignmentFlag, Qt::TextFlag, boundingRect(), layoutDirection()

By default, QPainter draws text anti-aliased.

Note
The y-coordinate of rectangle is used as the top of the font.

Definition at line 6528 of file qpainter.cpp.

6529 {
6530 #ifdef QT_DEBUG_DRAW
6531  if (qt_show_painter_debug_output)
6532  printf("QPainter::drawText(), r=[%.2f,%.2f,%.2f,%.2f], flags=%d, str='%s'\n",
6533  r.x(), r.y(), r.width(), r.height(), flags, str.toLatin1().constData());
6534 #endif
6535 
6536  Q_D(QPainter);
6537 
6538  if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen)
6539  return;
6540 
6541  if (!d->extended)
6542  d->updateState(d->state);
6543 
6544  qt_format_text(d->state->font, r, flags, 0, str, br, 0, 0, 0, this);
6545 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *option, const QString &str, QRectF *brect, int tabstops, int *tabarray, int tabarraylen, QPainter *painter)
Definition: qpainter.cpp:8458
#define Q_D(Class)
Definition: qglobal.h:2482
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152

◆ drawText() [6/8]

void QPainter::drawText ( const QRect rectangle,
int  flags,
const QString text,
QRect boundingRect = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the given text within the provided rectangle 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.

Note
The y-coordinate of rectangle is used as the top of the font.

Definition at line 6450 of file qpainter.cpp.

6451 {
6452 #ifdef QT_DEBUG_DRAW
6453  if (qt_show_painter_debug_output)
6454  printf("QPainter::drawText(), r=[%d,%d,%d,%d], flags=%d, str='%s'\n",
6455  r.x(), r.y(), r.width(), r.height(), flags, str.toLatin1().constData());
6456 #endif
6457 
6458  Q_D(QPainter);
6459 
6460  if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen)
6461  return;
6462 
6463  if (!d->extended)
6464  d->updateState(d->state);
6465 
6466  QRectF bounds;
6467  qt_format_text(d->state->font, r, flags, 0, str, br ? &bounds : 0, 0, 0, 0, this);
6468  if (br)
6469  *br = bounds.toAlignedRect();
6470 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *option, const QString &str, QRectF *brect, int tabstops, int *tabarray, int tabarraylen, QPainter *painter)
Definition: qpainter.cpp:8458
#define Q_D(Class)
Definition: qglobal.h:2482
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ drawText() [7/8]

void QPainter::drawText ( int  x,
int  y,
int  width,
int  height,
int  flags,
const QString text,
QRect boundingRect = 0 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.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.

Note
The y-position is used as the top of the font.
See also
Qt::AlignmentFlag, Qt::TextFlag

Definition at line 960 of file qpainter.h.

961 {
962  drawText(QRect(x, y, w, h), flags, str, br);
963 }
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ drawText() [8/8]

void QPainter::drawText ( const QRectF rectangle,
const QString text,
const QTextOption option = QTextOption() 
)

Draws the given text in the rectangle specified using the option to control its positioning and orientation.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

By default, QPainter draws text anti-aliased.

Note
The y-coordinate of rectangle is used as the top of the font.

Definition at line 6627 of file qpainter.cpp.

6628 {
6629 #ifdef QT_DEBUG_DRAW
6630  if (qt_show_painter_debug_output)
6631  printf("QPainter::drawText(), r=[%.2f,%.2f,%.2f,%.2f], str='%s'\n",
6632  r.x(), r.y(), r.width(), r.height(), text.toLatin1().constData());
6633 #endif
6634 
6635  Q_D(QPainter);
6636 
6637  if (!d->engine || text.length() == 0 || pen().style() == Qt::NoPen)
6638  return;
6639 
6640  if (!d->extended)
6641  d->updateState(d->state);
6642 
6643  qt_format_text(d->state->font, r, 0, &o, text, 0, 0, 0, 0, this);
6644 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *option, const QString &str, QRectF *brect, int tabstops, int *tabarray, int tabarraylen, QPainter *painter)
Definition: qpainter.cpp:8458
#define Q_D(Class)
Definition: qglobal.h:2482
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433

◆ drawTextItem() [1/3]

void QPainter::drawTextItem ( const QPointF p,
const QTextItem ti 
)

Draws the text item ti at position p.

Warning
This function is not part of the public interface.
Since
4.1

This method ignores the painters background mode and color. drawText and qt_format_text have to do it themselves, as only they know the extents of the complete string.

It ignores the font set on the painter as the text item has one of its own.

The underline and strikeout parameters of the text items font are ignored aswell. You'll need to pass in the correct flags to get underlining and strikeout.

Definition at line 6864 of file qpainter.cpp.

Referenced by QFontEngineXLFD::bitmapForGlyphs(), QTextLine::draw(), drawMenuText(), and drawText().

6865 {
6866 #ifdef QT_DEBUG_DRAW
6867  if (qt_show_painter_debug_output)
6868  printf("QPainter::drawTextItem(), pos=[%.f,%.f], str='%s'\n",
6869  p.x(), p.y(), qPrintable(_ti.text()));
6870 #endif
6871 
6872  Q_D(QPainter);
6873 
6874  if (!d->engine)
6875  return;
6876 
6877 #ifndef QT_NO_DEBUG
6878  qt_painter_thread_test(d->device->devType(),
6879  "text and fonts",
6881 #endif
6882 
6883  QTextItemInt &ti = const_cast<QTextItemInt &>(static_cast<const QTextItemInt &>(_ti));
6884 
6885  if (!d->extended && d->state->bgMode == Qt::OpaqueMode) {
6886  QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
6887  fillRect(rect, d->state->bgBrush);
6888  }
6889 
6890  if (pen().style() == Qt::NoPen)
6891  return;
6892 
6893  const RenderHints oldRenderHints = d->state->renderHints;
6894  if (!d->state->renderHints & QPainter::Antialiasing && d->state->matrix.type() >= QTransform::TxScale) {
6895  // draw antialias decoration (underline/overline/strikeout) with
6896  // transformed text
6897 
6898  bool aa = true;
6899  const QTransform &m = d->state->matrix;
6900  if (d->state->matrix.type() < QTransform::TxShear) {
6901  bool isPlain90DegreeRotation =
6902  (qFuzzyIsNull(m.m11())
6903  && qFuzzyIsNull(m.m12() - qreal(1))
6904  && qFuzzyIsNull(m.m21() + qreal(1))
6905  && qFuzzyIsNull(m.m22())
6906  )
6907  ||
6908  (qFuzzyIsNull(m.m11() + qreal(1))
6909  && qFuzzyIsNull(m.m12())
6910  && qFuzzyIsNull(m.m21())
6911  && qFuzzyIsNull(m.m22() + qreal(1))
6912  )
6913  ||
6914  (qFuzzyIsNull(m.m11())
6915  && qFuzzyIsNull(m.m12() + qreal(1))
6916  && qFuzzyIsNull(m.m21() - qreal(1))
6917  && qFuzzyIsNull(m.m22())
6918  )
6919  ;
6920  aa = !isPlain90DegreeRotation;
6921  }
6922  if (aa)
6924  }
6925 
6926  if (!d->extended)
6927  d->updateState(d->state);
6928 
6929  if (!ti.glyphs.numGlyphs) {
6930  // nothing to do
6931  } else if (ti.fontEngine->type() == QFontEngine::Multi) {
6932  QFontEngineMulti *multi = static_cast<QFontEngineMulti *>(ti.fontEngine);
6933 
6934  const QGlyphLayout &glyphs = ti.glyphs;
6935  int which = glyphs.glyphs[0] >> 24;
6936 
6937  qreal x = p.x();
6938  qreal y = p.y();
6939 
6940  bool rtl = ti.flags & QTextItem::RightToLeft;
6941  if (rtl)
6942  x += ti.width.toReal();
6943 
6944  int start = 0;
6945  int end, i;
6946  for (end = 0; end < ti.glyphs.numGlyphs; ++end) {
6947  const int e = glyphs.glyphs[end] >> 24;
6948  if (e == which)
6949  continue;
6950 
6951 
6952  QTextItemInt ti2 = ti.midItem(multi->engine(which), start, end - start);
6953  ti2.width = 0;
6954  // set the high byte to zero and calc the width
6955  for (i = start; i < end; ++i) {
6956  glyphs.glyphs[i] = glyphs.glyphs[i] & 0xffffff;
6957  ti2.width += ti.glyphs.effectiveAdvance(i);
6958  }
6959 
6960  if (rtl)
6961  x -= ti2.width.toReal();
6962 
6963  d->engine->drawTextItem(QPointF(x, y), ti2);
6964 
6965  if (!rtl)
6966  x += ti2.width.toReal();
6967 
6968  // reset the high byte for all glyphs and advance to the next sub-string
6969  const int hi = which << 24;
6970  for (i = start; i < end; ++i) {
6971  glyphs.glyphs[i] = hi | glyphs.glyphs[i];
6972  }
6973 
6974  // change engine
6975  start = end;
6976  which = e;
6977  }
6978 
6979  QTextItemInt ti2 = ti.midItem(multi->engine(which), start, end - start);
6980  ti2.width = 0;
6981  // set the high byte to zero and calc the width
6982  for (i = start; i < end; ++i) {
6983  glyphs.glyphs[i] = glyphs.glyphs[i] & 0xffffff;
6984  ti2.width += ti.glyphs.effectiveAdvance(i);
6985  }
6986 
6987  if (rtl)
6988  x -= ti2.width.toReal();
6989 
6990  if (d->extended)
6991  d->extended->drawTextItem(QPointF(x, y), ti2);
6992  else
6993  d->engine->drawTextItem(QPointF(x,y), ti2);
6994 
6995  // reset the high byte for all glyphs
6996  const int hi = which << 24;
6997  for (i = start; i < end; ++i)
6998  glyphs.glyphs[i] = hi | glyphs.glyphs[i];
6999 
7000  } else {
7001  if (d->extended)
7002  d->extended->drawTextItem(p, ti);
7003  else
7004  d->engine->drawTextItem(p, ti);
7005  }
7006  drawTextItemDecoration(this, p, ti.fontEngine, ti.underlineStyle, ti.flags, ti.width.toReal(),
7007  ti.charFormat);
7008 
7009  if (d->state->renderHints != oldRenderHints) {
7010  d->state->renderHints = oldRenderHints;
7011  if (d->extended)
7012  d->extended->renderHintsChanged();
7013  else
7014  d->state->dirtyFlags |= QPaintEngine::DirtyHints;
7015  }
7016 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
HB_Glyph * glyphs
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
#define Q_D(Class)
Definition: qglobal.h:2482
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
Internal QTextItem.
static bool supportsThreadedFontRendering()
Returns true if font rendering is supported outside the GUI thread, false otherwise.
static bool qt_painter_thread_test(int devType, const char *what, bool extraCondition=false)
Definition: qpainter.cpp:156
QTextItemInt midItem(QFontEngine *fontEngine, int firstGlyphIndex, int numGlyphs) const
qreal toReal() const
Definition: qfixed_p.h:77
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
#define qPrintable(string)
Definition: qglobal.h:1750
static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const QFontEngine *fe, QTextCharFormat::UnderlineStyle underlineStyle, QTextItem::RenderFlags flags, qreal width, const QTextCharFormat &charFormat)
Definition: qpainter.cpp:6738
bool end()
Ends painting.
Definition: qpainter.cpp:1929
QFontEngine * engine(int at) const
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
static qreal toReal(Register *reg, int type, bool *ok=0)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ drawTextItem() [2/3]

void QPainter::drawTextItem ( int  x,
int  y,
const QTextItem ti 
)
inline
Warning
This function is not part of the public interface. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 892 of file qpainter.h.

893 {
894  drawTextItem(QPointF(x, y), ti);
895 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawTextItem(const QPointF &p, const QTextItem &ti)
Draws the text item ti at position p.
Definition: qpainter.cpp:6864

◆ drawTextItem() [3/3]

void QPainter::drawTextItem ( const QPoint p,
const QTextItem ti 
)
inline

Draws the text item ti at position p.

Warning
This function is not part of the public interface. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 950 of file qpainter.h.

951 {
952  drawTextItem(QPointF(p), ti);
953 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void drawTextItem(const QPointF &p, const QTextItem &ti)
Draws the text item ti at position p.
Definition: qpainter.cpp:6864

◆ drawTiledPixmap() [1/3]

void QPainter::drawTiledPixmap ( const QRectF rectangle,
const QPixmap pixmap,
const QPointF position = QPointF() 
)

Draws a tiled pixmap, inside the given rectangle with its origin at the given position.

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.

See also
drawPixmap()

Definition at line 7146 of file qpainter.cpp.

Referenced by QRenderRule::drawBackgroundImage(), QCommonStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QWidgetPrivate::drawWidget(), QPicture::exec(), fillRegion(), QDeclarativeImage::paint(), QGtkPainter::paintBox(), QGtkPainter::paintBoxGap(), QPainterReplayer::process(), and qt_mac_fill_background().

7147 {
7148 #ifdef QT_DEBUG_DRAW
7149  if (qt_show_painter_debug_output)
7150  printf("QPainter::drawTiledPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], offset=[%.2f,%.2f]\n",
7151  r.x(), r.y(), r.width(), r.height(),
7152  pixmap.width(), pixmap.height(),
7153  sp.x(), sp.y());
7154 #endif
7155 
7156  Q_D(QPainter);
7157  if (!d->engine || pixmap.isNull() || r.isEmpty())
7158  return;
7159 
7160 #ifndef QT_NO_DEBUG
7161  qt_painter_thread_test(d->device->devType(), "drawTiledPixmap()", true);
7162 #endif
7163 
7164  qreal sw = pixmap.width();
7165  qreal sh = pixmap.height();
7166  qreal sx = sp.x();
7167  qreal sy = sp.y();
7168  if (sx < 0)
7169  sx = qRound(sw) - qRound(-sx) % qRound(sw);
7170  else
7171  sx = qRound(sx) % qRound(sw);
7172  if (sy < 0)
7173  sy = qRound(sh) - -qRound(sy) % qRound(sh);
7174  else
7175  sy = qRound(sy) % qRound(sh);
7176 
7177 
7178  if (d->extended) {
7179  d->extended->drawTiledPixmap(r, pixmap, QPointF(sx, sy));
7180  return;
7181  }
7182 
7183  if (d->state->bgMode == Qt::OpaqueMode && pixmap.isQBitmap())
7184  fillRect(r, d->state->bgBrush);
7185 
7186  d->updateState(d->state);
7187  if ((d->state->matrix.type() > QTransform::TxTranslate
7188  && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
7189  || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
7190  {
7191  save();
7194  setBrush(QBrush(d->state->pen.color(), pixmap));
7195  setPen(Qt::NoPen);
7196 
7197  // If there is no rotation involved we have to make sure we use the
7198  // antialiased and not the aliased coordinate system by rounding the coordinates.
7199  if (d->state->matrix.type() <= QTransform::TxScale) {
7200  const QPointF p = roundInDeviceCoordinates(r.topLeft(), d->state->matrix);
7201 
7202  if (d->state->matrix.type() <= QTransform::TxTranslate) {
7203  sx = qRound(sx);
7204  sy = qRound(sy);
7205  }
7206 
7207  setBrushOrigin(QPointF(r.x()-sx, r.y()-sy));
7208  drawRect(QRectF(p, r.size()));
7209  } else {
7210  setBrushOrigin(QPointF(r.x()-sx, r.y()-sy));
7211  drawRect(r);
7212  }
7213  restore();
7214  return;
7215  }
7216 
7217  qreal x = r.x();
7218  qreal y = r.y();
7219  if (d->state->matrix.type() == QTransform::TxTranslate
7220  && !d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
7221  x += d->state->matrix.dx();
7222  y += d->state->matrix.dy();
7223  }
7224 
7225  d->engine->drawTiledPixmap(QRectF(x, y, r.width(), r.height()), pixmap, QPointF(sx, sy));
7226 }
void setBackgroundMode(Qt::BGMode mode)
Sets the background mode of the painter to the given mode.
Definition: qpainter.cpp:3998
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
#define Q_D(Class)
Definition: qglobal.h:2482
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
static QPointF roundInDeviceCoordinates(const QPointF &p, const QTransform &m)
Definition: qpainter.cpp:5518
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isQBitmap() const
Returns true if this is a QBitmap; otherwise returns false.
Definition: qpixmap.cpp:599
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
static bool qt_painter_thread_test(int devType, const char *what, bool extraCondition=false)
Definition: qpainter.cpp:156
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ drawTiledPixmap() [2/3]

void QPainter::drawTiledPixmap ( int  x,
int  y,
int  w,
int  h,
const QPixmap pm,
int  sx = 0,
int  sy = 0 
)
inline

Definition at line 840 of file qpainter.h.

841 {
842  drawTiledPixmap(QRectF(x, y, w, h), pm, QPointF(sx, sy));
843 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
Definition: qpainter.cpp:7146

◆ drawTiledPixmap() [3/3]

void QPainter::drawTiledPixmap ( const QRect rectangle,
const QPixmap pixmap,
const QPoint position = QPoint() 
)
inline

Draws a tiled pixmap, inside the given rectangle with its origin at the given position.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 835 of file qpainter.h.

836 {
837  drawTiledPixmap(QRectF(rect), pm, QPointF(offset));
838 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
Definition: qpainter.cpp:7146

◆ end()

bool QPainter::end ( )

Ends painting.

Any resources used while painting are released. You don't normally need to call this since it is called by the destructor.

Returns true if the painter is no longer active; otherwise returns false.

See also
begin(), isActive()

Definition at line 1929 of file qpainter.cpp.

Referenced by _q_paintIntoCache(), QFontEngine::alphaMapForGlyph(), alphaMapFromPath(), begin(), QFontEngineXLFD::bitmapForGlyphs(), blendCursor(), QGraphicsItem::boundingRegion(), buttonChange(), QDragManager::drag(), QPixmapColorizeFilter::draw(), QPixmapDropShadowFilter::draw(), QPainterPrivate::draw_helper(), QAlphaPaintEnginePrivate::drawAlphaImage(), QMacStylePrivate::drawCombobox(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QGraphicsScenePrivate::drawItemHelper(), QDeclarativeTextPrivate::drawOutline(), QOpenGLPaintEngine::drawPixmap(), QPlastiqueStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMacStylePrivate::drawTableHeader(), drawTextItem(), QOpenGLPaintEngine::drawTiledPixmap(), QTraceWindowSurface::endPaint(), QX11PaintEnginePrivate::fillPolygon_dev(), QDeclarativeRectangle::generateBorderedRect(), QCommonStyle::generatedIconPixmap(), QDeclarativeRectangle::generateRoundedRect(), make_widget_eventUPP(), QColorWell::mouseMoveEvent(), QColorShowLabel::mouseMoveEvent(), QBlittablePixmapData::paintEngine(), QTipLabel::paintEvent(), QGraphicsView::paintEvent(), QSvgIconEngine::pixmap(), QGraphicsItemEffectSourcePrivate::pixmap(), qt_mac_read_fontsmoothing_settings(), qt_plastique_draw_gradient(), QSvgIOHandler::read(), QWidgetPrivate::render_helper(), QTreeViewPrivate::renderTreeToPixmapForAnimation(), QPixmap::scroll(), QItemDelegate::selected(), QTabBarPrivate::setupMovableTab(), QHeaderViewPrivate::setupSectionIndicator(), QWidgetPrivate::setWindowOpacity_sys(), QWidgetBackingStore::showYellowThing(), QMacStyle::styleHint(), toVGImageWithOpacity(), toVGImageWithOpacitySubRect(), ShaderEffect::updateRenderTargets(), and ~QPainter().

1930 {
1931 #ifdef QT_DEBUG_DRAW
1932  if (qt_show_painter_debug_output)
1933  printf("QPainter::end()\n");
1934 #endif
1935  Q_D(QPainter);
1936 
1937  if (!d->engine) {
1938  qWarning("QPainter::end: Painter not active, aborted");
1940  return false;
1941  }
1942 
1943  if (d->refcount > 1) {
1944  d->detachPainterPrivate(this);
1945  return true;
1946  }
1947 
1948  bool ended = true;
1949 
1950  if (d->engine->isActive()) {
1951  ended = d->engine->end();
1952  d->updateState(0);
1953 
1954  --d->device->painters;
1955  if (d->device->painters == 0) {
1956  d->engine->setPaintDevice(0);
1957  d->engine->setActive(false);
1958  }
1959  }
1960 
1961  if (d->states.size() > 1) {
1962  qWarning("QPainter::end: Painter ended with %d saved states",
1963  d->states.size());
1964  }
1965 
1966  if (d->engine->autoDestruct()) {
1967  delete d->engine;
1968  }
1969 
1970  if (d->emulationEngine) {
1971  delete d->emulationEngine;
1972  d->emulationEngine = 0;
1973  }
1974 
1975  if (d->extended) {
1976  d->extended = 0;
1977  }
1978 
1980 
1981  return ended;
1982 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static void qt_cleanup_painter_state(QPainterPrivate *d)
Definition: qpainter.cpp:1714
Q_CORE_EXPORT void qWarning(const char *,...)

◆ endNativePainting()

void QPainter::endNativePainting ( )

Restores the painter after manually issuing native painting commands.

Since
4.6

Lets the painter restore any native state that it relies on before calling any other painter commands.

See also
beginNativePainting()

Definition at line 2056 of file qpainter.cpp.

Referenced by ShaderEffectItem::paint().

2057 {
2058  Q_D(const QPainter);
2059  if (!d->engine) {
2060  qWarning("QPainter::beginNativePainting: Painter not active");
2061  return;
2062  }
2063 
2064  if (d->extended)
2065  d->extended->endNativePainting();
2066  else
2067  d->engine->syncState();
2068 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ eraseRect() [1/3]

void QPainter::eraseRect ( const QRectF rectangle)

Erases the area inside the given rectangle.

Equivalent to calling

fillRect(rectangle, background()).
See also
fillRect()

Definition at line 7332 of file qpainter.cpp.

Referenced by QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QComboBoxPrivateScroller::paintEvent(), QColorLuminancePicker::paintEvent(), and QWidget::update().

7333 {
7334  Q_D(QPainter);
7335 
7336  fillRect(r, d->state->bgBrush);
7337 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ eraseRect() [2/3]

void QPainter::eraseRect ( int  x,
int  y,
int  width,
int  height 
)
inline

Erases the area inside the rectangle beginning at (x, y) with the given width and height.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 779 of file qpainter.h.

780 {
781  eraseRect(QRectF(x, y, w, h));
782 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void eraseRect(const QRectF &)
Erases the area inside the given rectangle.
Definition: qpainter.cpp:7332

◆ eraseRect() [3/3]

void QPainter::eraseRect ( const QRect rectangle)
inline

Erases the area inside the given rectangle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 774 of file qpainter.h.

775 {
776  eraseRect(QRectF(rect));
777 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void eraseRect(const QRectF &)
Erases the area inside the given rectangle.
Definition: qpainter.cpp:7332

◆ fillPath()

void QPainter::fillPath ( const QPainterPath path,
const QBrush brush 
)

Fills the given path using the given brush.

The outline is not drawn.

Alternatively, you can specify a QColor instead of a QBrush; the QBrush constructor (taking a QColor argument) will automatically create a solid pattern brush.

See also
drawPath()

Definition at line 3456 of file qpainter.cpp.

Referenced by QRenderRule::drawBackground(), QCDEStyle::drawControl(), QMacStyle::drawPrimitive(), QPaintEngine::drawTextItem(), QGraphicsWidget::paintWindowFrame(), and QPainterReplayer::process().

3457 {
3458  Q_D(QPainter);
3459 
3460  if (!d->engine) {
3461  qWarning("QPainter::fillPath: Painter not active");
3462  return;
3463  }
3464 
3465  if (path.isEmpty())
3466  return;
3467 
3468  if (d->extended) {
3469  const QGradient *g = brush.gradient();
3470  if (!g || g->coordinateMode() == QGradient::LogicalMode) {
3471  d->extended->fill(qtVectorPathForPath(path), brush);
3472  return;
3473  }
3474  }
3475 
3476  QBrush oldBrush = d->state->brush;
3477  QPen oldPen = d->state->pen;
3478 
3479  setPen(Qt::NoPen);
3480  setBrush(brush);
3481 
3482  drawPath(path);
3483 
3484  // Reset old state
3485  setPen(oldPen);
3486  setBrush(oldBrush);
3487 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
const QVectorPath & qtVectorPathForPath(const QPainterPath &path)
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
Q_CORE_EXPORT void qWarning(const char *,...)
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047

◆ fillRect() [1/12]

void QPainter::fillRect ( const QRectF rectangle,
const QBrush brush 
)

Fills the given rectangle with the brush specified.

Alternatively, you can specify a QColor instead of a QBrush; the QBrush constructor (taking a QColor argument) will automatically create a solid pattern brush.

See also
drawRect()

Definition at line 7420 of file qpainter.cpp.

Referenced by _q_paintItem(), QXlibWindowSurface::beginPaint(), QRasterWindowSurface::beginPaint(), QWSMemorySurface::beginPaint(), QFontEngineXLFD::bitmapForGlyphs(), QmlJSDebugger::ToolBarColorBox::createDragPixmap(), QFbScreen::doRedraw(), QDragManager::drag(), QPixmapDropShadowFilter::draw(), QTextLine::draw(), QGraphicsOpacityEffect::draw(), QPainterPrivate::draw_helper(), QItemDelegate::drawBackground(), QGraphicsView::drawBackground(), QGraphicsScene::drawBackground(), QRenderRule::drawBackground(), QWindowsCEStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QStyleSheetStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCDEStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QTextLayout::drawCursor(), QItemDelegate::drawDisplay(), QGraphicsView::drawForeground(), QGraphicsScene::drawForeground(), QStyle::drawItemText(), QTextDocumentLayoutPrivate::drawListItem(), QWindowsMobileStylePrivate::drawPanelItemViewSelected(), drawPixmap(), QWindowsCEStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QStyleSheetStyle::drawPrimitive(), QWindowsMobileStylePrivate::drawScrollbarGrip(), QWindowsMobileStylePrivate::drawScrollbarGroove(), QWindowsMobileStylePrivate::drawScrollbarHandleDown(), QWindowsMobileStylePrivate::drawScrollbarHandleUp(), QWindowsMobileStylePrivate::drawTabBarTab(), drawTabBase(), drawTabShape(), drawTextItem(), drawTextItemDecoration(), drawTiledPixmap(), QWidgetPrivate::drawWidget(), QWindowsCEStylePrivate::drawWinCEShades(), QWindowsCEStylePrivate::drawWinCEShadesSunken(), QWindowsCEStylePrivate::drawWinShades(), eraseRect(), QScriptEdit::extraAreaPaintEvent(), QImage::fill(), fillBackground(), fillRect(), fillRegion(), QCommonStyle::generatedIconPixmap(), make_widget_eventUPP(), QTriangulator< T >::ComplexToSimple::Event::operator<(), QDecorationWindows::paint(), QDecorationStyled::paint(), QDeclarativePaintedItem::paint(), QDeclarativeRectangle::paint(), QComboMenuDelegate::paint(), QDecorationWindows::paintButton(), QDecorationDefault::paintButton(), QWellArray::paintCellContents(), QColorWell::paintCellContents(), QBlittablePixmapData::paintEngine(), QWorkspace::paintEvent(), QToolBar::paintEvent(), QMdiArea::paintEvent(), QPagePreview::paintEvent(), QSystemTrayIconSys::paintEvent(), QWizard::paintEvent(), QHeaderView::paintEvent(), QPlainTextEdit::paintEvent(), QGraphicsView::paintEvent(), QWizardAntiFlickerWidget::paintEvent(), QColorPicker::paintEvent(), QColorShowLabel::paintEvent(), QGraphicsWidget::paintWindowFrame(), QPainterReplayer::process(), qDrawPlainRect(), qDrawShadePanel(), qDrawWinShades(), qt_cleanlooks_draw_buttongradient(), qt_cleanlooks_draw_gradient(), qt_cleanlooks_draw_mdibutton(), qt_plastique_draw_gradient(), QTreeViewPrivate::renderTreeToPixmapForAnimation(), QItemDelegate::selected(), setPenAndDrawBackground(), QWidgetBackingStore::showYellowThing(), and ShaderEffect::updateRenderTargets().

7421 {
7422  Q_D(QPainter);
7423 
7424  if (!d->engine)
7425  return;
7426 
7427  if (d->extended) {
7428  const QGradient *g = brush.gradient();
7429  if (!g || g->coordinateMode() == QGradient::LogicalMode) {
7430  d->extended->fillRect(r, brush);
7431  return;
7432  }
7433  }
7434 
7435  QPen oldPen = pen();
7436  QBrush oldBrush = this->brush();
7437  setPen(Qt::NoPen);
7438  if (brush.style() == Qt::SolidPattern) {
7439  d->colorBrush.setStyle(Qt::SolidPattern);
7440  d->colorBrush.setColor(brush.color());
7441  setBrush(d->colorBrush);
7442  } else {
7443  setBrush(brush);
7444  }
7445 
7446  drawRect(r);
7447  setBrush(oldBrush);
7448  setPen(oldPen);
7449 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650

◆ fillRect() [2/12]

void QPainter::fillRect ( int  x,
int  y,
int  width,
int  height,
const QBrush brush 
)
inline

Fills the rectangle beginning at ({x}, {y}) with the given width and height, using the given brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 784 of file qpainter.h.

785 {
786  fillRect(QRect(x, y, w, h), b);
787 }
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ fillRect() [3/12]

void QPainter::fillRect ( const QRect rectangle,
const QBrush brush 
)

Fills the given rectangle with the specified brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 7461 of file qpainter.cpp.

7462 {
7463  Q_D(QPainter);
7464 
7465  if (!d->engine)
7466  return;
7467 
7468  if (d->extended) {
7469  const QGradient *g = brush.gradient();
7470  if (!g || g->coordinateMode() == QGradient::LogicalMode) {
7471  d->extended->fillRect(r, brush);
7472  return;
7473  }
7474  }
7475 
7476  QPen oldPen = pen();
7477  QBrush oldBrush = this->brush();
7478  setPen(Qt::NoPen);
7479  if (brush.style() == Qt::SolidPattern) {
7480  d->colorBrush.setStyle(Qt::SolidPattern);
7481  d->colorBrush.setColor(brush.color());
7482  setBrush(d->colorBrush);
7483  } else {
7484  setBrush(brush);
7485  }
7486 
7487  drawRect(r);
7488  setBrush(oldBrush);
7489  setPen(oldPen);
7490 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650

◆ fillRect() [4/12]

void QPainter::fillRect ( const QRectF rectangle,
const QColor color 
)

Fills the given rectangle with the color specified.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

Definition at line 7532 of file qpainter.cpp.

7533 {
7534  Q_D(QPainter);
7535 
7536  if (!d->engine)
7537  return;
7538 
7539  if (d->extended) {
7540  d->extended->fillRect(r, color);
7541  return;
7542  }
7543 
7544  fillRect(r, QBrush(color));
7545 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ fillRect() [5/12]

void QPainter::fillRect ( int  x,
int  y,
int  width,
int  height,
const QColor color 
)
inline

Fills the rectangle beginning at ({x}, {y}) with the given width and height, using the given color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

Definition at line 789 of file qpainter.h.

790 {
791  fillRect(QRect(x, y, w, h), b);
792 }
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ fillRect() [6/12]

void QPainter::fillRect ( const QRect rectangle,
const QColor color 
)

Fills the given rectangle with the color specified.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

Definition at line 7505 of file qpainter.cpp.

7506 {
7507  Q_D(QPainter);
7508 
7509  if (!d->engine)
7510  return;
7511 
7512  if (d->extended) {
7513  d->extended->fillRect(r, color);
7514  return;
7515  }
7516 
7517  fillRect(r, QBrush(color));
7518 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ fillRect() [7/12]

void QPainter::fillRect ( int  x,
int  y,
int  width,
int  height,
Qt::GlobalColor  color 
)
inline

Fills the rectangle beginning at ({x}, {y}) with the given width and height, using the given color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

Definition at line 794 of file qpainter.h.

795 {
796  fillRect(QRect(x, y, w, h), QColor(c));
797 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
unsigned char c[8]
Definition: qnumeric_p.h:62
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ fillRect() [8/12]

void QPainter::fillRect ( const QRect rectangle,
Qt::GlobalColor  color 
)
inline

Fills the given rectangle with the specified color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

Definition at line 799 of file qpainter.h.

800 {
801  fillRect(r, QColor(c));
802 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
unsigned char c[8]
Definition: qnumeric_p.h:62
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ fillRect() [9/12]

void QPainter::fillRect ( const QRectF rectangle,
Qt::GlobalColor  color 
)
inline

Fills the given rectangle with the specified color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

Definition at line 804 of file qpainter.h.

805 {
806  fillRect(r, QColor(c));
807 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
unsigned char c[8]
Definition: qnumeric_p.h:62
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ fillRect() [10/12]

void QPainter::fillRect ( int  x,
int  y,
int  width,
int  height,
Qt::BrushStyle  style 
)
inline

Fills the rectangle beginning at ({x}, {y}) with the given width and height, using the brush style specified.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

Definition at line 809 of file qpainter.h.

810 {
811  fillRect(QRectF(x, y, w, h), QBrush(style));
812 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ fillRect() [11/12]

void QPainter::fillRect ( const QRect rectangle,
Qt::BrushStyle  style 
)
inline

Fills the given rectangle with the brush style specified.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

Definition at line 814 of file qpainter.h.

815 {
816  fillRect(QRectF(r), QBrush(style));
817 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ fillRect() [12/12]

void QPainter::fillRect ( const QRectF rectangle,
Qt::BrushStyle  style 
)
inline

Fills the given rectangle with the brush style specified.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.5

Definition at line 819 of file qpainter.h.

820 {
821  fillRect(r, QBrush(style));
822 }
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ font()

const QFont & QPainter::font ( ) const

Returns the currently set font used for drawing text.

See also
setFont(), drawText(), {QPainter::Settings}{Settings}

Definition at line 4312 of file qpainter.cpp.

Referenced by QSvgFontStyle::apply(), QDeclarativeTextLayout::draw(), QSvgText::draw(), QWindowsCEStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), drawGlyphRun(), drawStaticText(), and QFontFamilyDelegate::paint().

4313 {
4314  Q_D(const QPainter);
4315  if (!d->engine) {
4316  qWarning("QPainter::font: Painter not active");
4317  return d->fakeState()->font;
4318  }
4319  return d->state->font;
4320 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ fontInfo()

QFontInfo QPainter::fontInfo ( ) const

Returns the font info for the painter if the painter is active.

Otherwise, the return value is undefined.

See also
font(), isActive(), {QPainter::Settings}{Settings}

Definition at line 2095 of file qpainter.cpp.

2096 {
2097  Q_D(const QPainter);
2098  if (!d->engine) {
2099  qWarning("QPainter::fontInfo: Painter not active");
2100  return QFontInfo(QFont());
2101  }
2102  return QFontInfo(d->state->font);
2103 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QFontInfo class provides general information about fonts.
Definition: qfontinfo.h:54
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64

◆ fontMetrics()

QFontMetrics QPainter::fontMetrics ( ) const

Returns the font metrics for the painter if the painter is active.

Otherwise, the return value is undefined.

See also
font(), isActive(), {QPainter::Settings}{Settings}

Definition at line 2077 of file qpainter.cpp.

Referenced by QWindowsStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QGtkStyle::drawControl(), QMacStyle::drawControl(), QFontFamilyDelegate::paint(), and printPage().

2078 {
2079  Q_D(const QPainter);
2080  if (!d->engine) {
2081  qWarning("QPainter::fontMetrics: Painter not active");
2082  return QFontMetrics(QFont());
2083  }
2084  return QFontMetrics(d->state->font);
2085 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64

◆ hasClipping()

bool QPainter::hasClipping ( ) const

Returns true if clipping has been set; otherwise returns false.

See also
setClipping(), {QPainter::Clipping}{Clipping}

Definition at line 2499 of file qpainter.cpp.

Referenced by QWindowsXPStylePrivate::drawBackgroundDirectly(), QMacPrintEnginePrivate::newPage_helper(), QMacCGContext::QMacCGContext(), QWidget::render(), setClipping(), and QX11PaintEnginePrivate::systemStateChanged().

2500 {
2501  Q_D(const QPainter);
2502  if (!d->engine) {
2503  qWarning("QPainter::hasClipping: Painter not active");
2504  return false;
2505  }
2506  return d->state->clipEnabled && d->state->clipOperation != Qt::NoClip;
2507 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ initFrom()

void QPainter::initFrom ( const QWidget widget)

Initializes the painters pen, background and font to the same as the given widget.

This function is called automatically when the painter is opened on a QWidget.

See also
begin(), {QPainter::Settings}{Settings}

Definition at line 1558 of file qpainter.cpp.

Referenced by QPainterPrivate::attachPainterPrivate(), begin(), and QTabBarPrivate::setupMovableTab().

1559 {
1560  Q_ASSERT_X(widget, "QPainter::initFrom(const QWidget *widget)", "Widget cannot be 0");
1561  Q_D(QPainter);
1562  if (!d->engine) {
1563  qWarning("QPainter::initFrom: Painter not active, aborted");
1564  return;
1565  }
1566 
1567  const QPalette &pal = widget->palette();
1568  d->state->pen = QPen(pal.brush(widget->foregroundRole()), 0);
1569  d->state->bgBrush = pal.brush(widget->backgroundRole());
1570  d->state->deviceFont = QFont(widget->font(), const_cast<QWidget*> (widget));
1571  d->state->font = d->state->deviceFont;
1572  if (d->extended) {
1573  d->extended->penChanged();
1574  } else if (d->engine) {
1575  d->engine->setDirty(QPaintEngine::DirtyPen);
1576  d->engine->setDirty(QPaintEngine::DirtyBrush);
1577  d->engine->setDirty(QPaintEngine::DirtyFont);
1578  }
1579 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QPalette palette
the widget&#39;s palette
Definition: qwidget.h:180
QPointer< QWidget > widget
QFont font
the font currently set for the widget
Definition: qwidget.h:181
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QPalette::ColorRole backgroundRole() const
Returns the background role of the widget.
Definition: qwidget.cpp:4677
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
QPalette::ColorRole foregroundRole() const
Returns the foreground role.
Definition: qwidget.cpp:4728
Q_CORE_EXPORT void qWarning(const char *,...)
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61

◆ isActive()

bool QPainter::isActive ( ) const

Returns true if begin() has been called and end() has not yet been called; otherwise returns false.

See also
begin(), QPaintDevice::paintingActive()

Definition at line 1545 of file qpainter.cpp.

Referenced by QPainterPrivate::attachPainterPrivate(), device(), QPixmapConvolutionFilter::draw(), QPixmapBlurFilter::draw(), QWindowsXPStylePrivate::drawBackground(), QWidgetPrivate::drawWidget(), QTextDocument::print(), QPaintBuffer::processCommands(), qDrawBorderPixmap(), QGraphicsView::render(), QWidget::render(), QWidgetPrivate::render(), and ~QPainter().

1546 {
1547  Q_D(const QPainter);
1548  return d->engine;
1549 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ layoutDirection()

Qt::LayoutDirection QPainter::layoutDirection ( ) const

Returns the layout direction used by the painter when drawing text.

See also
QTextOption::textDirection(), setLayoutDirection(), drawText(), {QPainter::Settings}{Settings}

Definition at line 8729 of file qpainter.cpp.

Referenced by _q_paintItem(), QIcon::paint(), and qt_format_text().

8730 {
8731  Q_D(const QPainter);
8732  return d->state ? d->state->layoutDirection : Qt::LayoutDirectionAuto;
8733 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ matrix()

const QMatrix & QPainter::matrix ( ) const

Use worldTransform() instead.

See also
worldTransform()

Definition at line 3061 of file qpainter.cpp.

Referenced by clipPath(), and clipRegion().

3062 {
3063  return worldMatrix();
3064 }
const QMatrix & worldMatrix() const
Returns the world transformation matrix.
Definition: qpainter.cpp:3024

◆ matrixEnabled()

bool QPainter::matrixEnabled ( ) const

Use worldMatrixEnabled() instead

See also
worldMatrixEnabled()

Definition at line 3222 of file qpainter.cpp.

3223 {
3224  return worldMatrixEnabled();
3225 }
bool worldMatrixEnabled() const
Returns true if world transformation is enabled; otherwise returns false.
Definition: qpainter.cpp:3188

◆ opacity()

qreal QPainter::opacity ( ) const

Returns the opacity of the painter.

Since
4.2

The default value is 1.

Definition at line 2115 of file qpainter.cpp.

Referenced by _q_paintItem(), QSvgOpacityStyle::apply(), QSvgArc::draw(), QSvgLine::draw(), QSvgPolyline::draw(), QSvgText::draw(), QWindowsXPStylePrivate::drawBackground(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsScene::drawItems(), QWidget::render(), and setOpacity().

2116 {
2117  Q_D(const QPainter);
2118  if (!d->engine) {
2119  qWarning("QPainter::opacity: Painter not active");
2120  return 1.0;
2121  }
2122  return d->state->opacity;
2123 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ paintEngine()

QPaintEngine * QPainter::paintEngine ( ) const

Returns the paint engine that the painter is currently operating on if the painter is active; otherwise 0.

See also
isActive()

Definition at line 1991 of file qpainter.cpp.

Referenced by QPainterPrivate::attachPainterPrivate(), QPixmapConvolutionFilter::draw(), QPixmapBlurFilter::draw(), QPixmapColorizeFilter::draw(), QPixmapDropShadowFilter::draw(), QGraphicsBlurEffect::draw(), QGraphicsDropShadowEffect::draw(), QWindowsXPStylePrivate::drawBackground(), QWindowsXPStylePrivate::drawBackgroundDirectly(), QCommonStyle::drawComplexControl(), QMacStyle::drawComplexControl(), drawTextItemDecoration(), QVistaHelper::drawTitleBar(), XPThemeData::mask(), QPreviewPaintEngine::newPage(), QDecorationStyled::paint(), QDecorationDefault::paint(), QDeclarativePaintedItem::paint(), QDecorationDefault::paintButton(), QVistaBackButton::paintEvent(), QSystemTrayIconSys::paintEvent(), QPainterReplayer::process(), QPaintEngineExReplayer::process(), QPaintBuffer::processCommands(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), qDrawBorderPixmap(), QMacCGContext::QMacCGContext(), qt_vg_drawVGImage(), qt_vg_drawVGImageStencil(), qt_x11_get_brush_gc(), qt_x11_get_pen_gc(), QGLCustomShaderStage::removeFromPainter(), QWidget::render(), and QGLCustomShaderStage::setOnPainter().

1992 {
1993  Q_D(const QPainter);
1994  return d->engine;
1995 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ pen()

const QPen & QPainter::pen ( ) const

Returns the painter's current pen.

See also
setPen(), {QPainter::Settings}{Settings}

Definition at line 4152 of file qpainter.cpp.

Referenced by QSvgStrokeStyle::apply(), QSvgAnimateColor::apply(), QFontEngineBox::boundingBox(), QSvgArc::draw(), QSvgFont::draw(), QSvgLine::draw(), QSvgPolyline::draw(), QTextLayout::draw(), QSvgText::draw(), QGraphicsScenePrivate::draw(), QTextLine::draw(), QTextDocumentLayoutPrivate::drawBlock(), QPaintEnginePrivate::drawBoxTextItem(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QMacStyle::drawControl(), QTextLayout::drawCursor(), QTextDocumentLayoutPrivate::drawFrame(), QWindowsCEStyle::drawItemText(), QCleanlooksStyle::drawItemText(), QStyle::drawItemText(), QPaintEngine::drawPoints(), drawPoints(), QWindowsVistaStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), drawStaticText(), QWindowsMobileStylePrivate::drawTabBarTab(), QTextDocumentLayoutPrivate::drawTableCell(), drawText(), QCoreGraphicsPaintEngine::drawTextItem(), drawTextItem(), drawTextItemDecoration(), QWindowsCEStylePrivate::drawWinCEShades(), QWindowsCEStylePrivate::drawWinCEShadesSunken(), QWindowsCEStylePrivate::drawWinShades(), QPicture::exec(), fillRect(), generateWavyPixmap(), QTableView::paintEvent(), QLineEdit::paintEvent(), QStaticTextPrivate::paintText(), qDrawPlainRect(), qDrawShadeLine(), qDrawShadePanel(), qDrawShadeRect(), qDrawWinShades(), qt_plastique_draw_frame(), qt_plastique_drawFrame(), qt_plastique_drawShadedPanel(), setPen(), QSvgNode::strokeWidth(), and QPicturePaintEngine::writeCmdLength().

4153 {
4154  Q_D(const QPainter);
4155  if (!d->engine) {
4156  qWarning("QPainter::pen: Painter not active");
4157  return d->fakeState()->pen;
4158  }
4159  return d->state->pen;
4160 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ redirected()

QPaintDevice * QPainter::redirected ( const QPaintDevice device,
QPoint offset = 0 
)
static

Using QWidget::render() obsoletes the use of this function.

Note
This class or function is threadsafe.

Returns the replacement for given device. The optional out parameter offset returns the offset within the replaced device.

Warning
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.
See also
setRedirected(), restoreRedirected()

Definition at line 8391 of file qpainter.cpp.

Referenced by begin(), QAxHostWidget::paintEvent(), qt_mac_fill_background(), and QWidgetPrivate::render().

8392 {
8393  Q_ASSERT(device != 0);
8394 
8395  if (device->devType() == QInternal::Widget) {
8396  const QWidgetPrivate *widgetPrivate = static_cast<const QWidget *>(device)->d_func();
8397  if (widgetPrivate->redirectDev)
8398  return widgetPrivate->redirected(offset);
8399  }
8400 
8401  if (!globalRedirectionAtomic() || *globalRedirectionAtomic() == 0)
8402  return 0;
8403 
8404  QMutexLocker locker(globalRedirectionsMutex());
8405  QPaintDeviceRedirectionList *redirections = globalRedirections();
8406  Q_ASSERT(redirections != 0);
8407  for (int i = redirections->size()-1; i >= 0; --i)
8408  if (redirections->at(i) == device) {
8409  if (offset)
8410  *offset = redirections->at(i).offset;
8411  return redirections->at(i).replacement;
8412  }
8413  if (offset)
8414  *offset = QPoint(0, 0);
8415  return 0;
8416 }
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
QPaintDevice * redirected(QPoint *offset) const
Definition: qwidget_p.h:628
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual int devType() const
Definition: qpaintdevice.h:167
QPaintDevice * redirectDev
Definition: qwidget_p.h:706
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ renderHints()

QPainter::RenderHints QPainter::renderHints ( ) const

Returns a flag that specifies the rendering hints that are set for this painter.

See also
testRenderHint(), {QPainter::Rendering Quality}{Rendering Quality}

Definition at line 7675 of file qpainter.cpp.

Referenced by _q_paintIntoCache(), QGraphicsOpacityEffect::draw(), QRenderRule::drawBackground(), QTextDocumentLayoutPrivate::drawBorder(), QRenderRule::drawBorder(), QRenderRule::drawBorderImage(), QTextLayout::drawCursor(), drawImage(), QGraphicsScenePrivate::drawItemHelper(), QRenderRule::drawOutline(), drawPixmap(), QPlastiqueStyle::drawPrimitive(), drawTiledPixmap(), QGraphicsProxyWidget::paint(), QGraphicsView::paintEvent(), QPainterReplayer::process(), and QWidgetPrivate::render_helper().

7676 {
7677  Q_D(const QPainter);
7678 
7679  if (!d->engine)
7680  return 0;
7681 
7682  return d->state->renderHints;
7683 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ resetMatrix()

void QPainter::resetMatrix ( )

Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldMatrix(), setViewport() and setWindow().

It is advisable to use resetTransform() instead of this function to preserve the properties of perspective transformations.

See also
{QPainter::Coordinate Transformations}{Coordinate Transformations}

Definition at line 3137 of file qpainter.cpp.

3138 {
3139  resetTransform();
3140 }
void resetTransform()
Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldTransform(), setViewport() and setWindow().
Definition: qpainter.cpp:9598

◆ resetTransform()

void QPainter::resetTransform ( )

Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldTransform(), setViewport() and setWindow().

See also
{Coordinate Transformations}

Definition at line 9598 of file qpainter.cpp.

Referenced by QPainterPrivate::draw_helper(), and resetMatrix().

9599 {
9600  Q_D(QPainter);
9601 #ifdef QT_DEBUG_DRAW
9602  if (qt_show_painter_debug_output)
9603  printf("QPainter::resetMatrix()\n");
9604 #endif
9605  if (!d->engine) {
9606  qWarning("QPainter::resetMatrix: Painter not active");
9607  return;
9608  }
9609 
9610  d->state->wx = d->state->wy = d->state->vx = d->state->vy = 0; // default view origins
9611  d->state->ww = d->state->vw = d->device->metric(QPaintDevice::PdmWidth);
9612  d->state->wh = d->state->vh = d->device->metric(QPaintDevice::PdmHeight);
9613  d->state->worldMatrix = QTransform();
9614  setMatrixEnabled(false);
9615  setViewTransformEnabled(false);
9616  if (d->extended)
9617  d->extended->transformChanged();
9618  else
9619  d->state->dirtyFlags |= QPaintEngine::DirtyTransform;
9620 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
void setMatrixEnabled(bool enabled)
Use setWorldMatrixEnabled() instead.
Definition: qpainter.cpp:3209
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
void setViewTransformEnabled(bool enable)
Enables view transformations if enable is true, or disables view transformations if enable is false...
Definition: qpainter.cpp:7906
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ restore()

void QPainter::restore ( )

Restores the current painter state (pops a saved state off the stack).

See also
save()

Definition at line 1620 of file qpainter.cpp.

Referenced by _q_paintItem(), QFontEngineBox::boundingBox(), QPainterPrivate::detachPainterPrivate(), QSvgFont::draw(), QSvgTinyDocument::draw(), QTextLayout::draw(), QGraphicsScenePrivate::draw(), QTextLine::draw(), QGraphicsOpacityEffect::draw(), QGraphicsScene::drawBackground(), QWindowsXPStylePrivate::drawBackground(), QRenderRule::drawBackgroundImage(), QTextDocumentLayoutPrivate::drawBorder(), QPaintEnginePrivate::drawBoxTextItem(), QWindowsVistaStyle::drawComplexControl(), QWindowsCEStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QStyleSheetStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QSplashScreen::drawContents(), QDeclarativeTextInput::drawContents(), QTextDocument::drawContents(), QTextControl::drawContents(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QCDEStyle::drawControl(), QWindowsMobileStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QStyleHelper::drawDial(), QItemDelegate::drawDisplay(), QGraphicsScene::drawForeground(), QTextDocumentLayoutPrivate::drawFrameDecoration(), QX11PaintEngine::drawFreetype(), drawImage(), QTextDocumentLayoutPrivate::drawListItem(), QPlastiqueStylePrivate::drawPartialFrame(), drawPicture(), drawPixmap(), QPaintEngine::drawPoints(), drawPoints(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QTreeView::drawRow(), QWindowsMobileStylePrivate::drawTabBarTab(), QPaintEngine::drawTextItem(), drawTextItemDecoration(), drawTiledPixmap(), QWidgetPrivate::drawWidget(), QPaintBufferEngine::end(), QPicture::exec(), fillBackground(), fillRegion(), QAlphaPaintEngine::flushAndInit(), QDecorationStyled::paint(), ShaderEffectItem::paint(), QItemDelegate::paint(), QDeclarativeImage::paint(), QFontFamilyDelegate::paint(), QDeclarativeText::paint(), QGraphicsTextItem::paint(), QCommandLinkButton::paintEvent(), QLabel::paintEvent(), QListView::paintEvent(), QHeaderView::paintEvent(), QGraphicsView::paintEvent(), QStaticTextPrivate::paintText(), QGraphicsWidget::paintWindowFrame(), printPage(), QPainterReplayer::process(), qDrawEdge(), qDrawRoundedCorners(), qt_format_text(), QGraphicsScene::render(), QGraphicsView::render(), QRenderRule::unsetClip(), and QCommonStylePrivate::viewItemDrawText().

1621 {
1622 #ifdef QT_DEBUG_DRAW
1623  if (qt_show_painter_debug_output)
1624  printf("QPainter::restore()\n");
1625 #endif
1626  Q_D(QPainter);
1627  if (d->states.size()<=1) {
1628  qWarning("QPainter::restore: Unbalanced save/restore");
1629  return;
1630  } else if (!d->engine) {
1631  qWarning("QPainter::restore: Painter not active");
1632  return;
1633  }
1634 
1635  QPainterState *tmp = d->state;
1636  d->states.pop_back();
1637  d->state = d->states.back();
1638  d->txinv = false;
1639 
1640  if (d->extended) {
1641  d->checkEmulation();
1642  d->extended->setState(d->state);
1643  delete tmp;
1644  return;
1645  }
1646 
1647  // trigger clip update if the clip path/region has changed since
1648  // last save
1649  if (!d->state->clipInfo.isEmpty()
1651  // reuse the tmp state to avoid any extra allocs...
1653  tmp->clipOperation = Qt::NoClip;
1654  tmp->clipPath = QPainterPath();
1655  d->engine->updateState(*tmp);
1656  // replay the list of clip states,
1657  for (int i=0; i<d->state->clipInfo.size(); ++i) {
1658  const QPainterClipInfo &info = d->state->clipInfo.at(i);
1659  tmp->matrix = info.matrix;
1660  tmp->matrix *= d->state->redirectionMatrix;
1661  tmp->clipOperation = info.operation;
1662  if (info.clipType == QPainterClipInfo::RectClip) {
1664  tmp->clipRegion = info.rect;
1665  } else if (info.clipType == QPainterClipInfo::RegionClip) {
1667  tmp->clipRegion = info.region;
1668  } else { // clipType == QPainterClipInfo::PathClip
1670  tmp->clipPath = info.path;
1671  }
1672  d->engine->updateState(*tmp);
1673  }
1674 
1675 
1676  //Since we've updated the clip region anyway, pretend that the clip path hasn't changed:
1677  d->state->dirtyFlags &= ~(QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipRegion);
1680  }
1681 
1682  d->updateState(d->state);
1683  delete tmp;
1684 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QRegion clipRegion
Definition: qpainter_p.h:155
static mach_timebase_info_data_t info
Qt::ClipOperation operation
Definition: qpainter_p.h:119
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
uint changeFlags
Definition: qpainter_p.h:176
ClipType clipType
Definition: qpainter_p.h:117
QPaintEngine::DirtyFlags dirtyFlags
Definition: qpaintengine.h:325
QTransform matrix
Definition: qpainter_p.h:161
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::ClipOperation clipOperation
Definition: qpainter_p.h:157
QPainterPath path
Definition: qpainter_p.h:120
Q_CORE_EXPORT void qWarning(const char *,...)
QTransform matrix
Definition: qpainter_p.h:118
QPainterPath clipPath
Definition: qpainter_p.h:156

◆ restoreRedirected()

void QPainter::restoreRedirected ( const QPaintDevice device)
static

Using QWidget::render() obsoletes the use of this function.

Note
This class or function is threadsafe.

Restores the previous redirection for the given device after a call to setRedirected().

Warning
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.
See also
redirected()

Definition at line 8344 of file qpainter.cpp.

8345 {
8346  Q_ASSERT(device != 0);
8347  QMutexLocker locker(globalRedirectionsMutex());
8348  QPaintDeviceRedirectionList *redirections = globalRedirections();
8349  Q_ASSERT(redirections != 0);
8350  for (int i = redirections->size()-1; i >= 0; --i) {
8351  if (redirections->at(i) == device) {
8352  globalRedirectionAtomic()->deref();
8353  const int internalWidgetRedirectionIndex = redirections->at(i).internalWidgetRedirectionIndex;
8354  redirections->removeAt(i);
8355  // Restore the internal widget redirection, i.e. remove it from the global
8356  // redirection list and put it back into QWidgetPrivate. The index is only set when
8357  // someone call QPainter::setRedirected in a widget's paint event and we internally
8358  // have a redirection set (typically set in QWidgetPrivate::drawWidget).
8359  if (internalWidgetRedirectionIndex >= 0) {
8360  Q_ASSERT(internalWidgetRedirectionIndex < redirections->size());
8361  const QPaintDeviceRedirection &redirectionDevice = redirections->at(internalWidgetRedirectionIndex);
8362  QWidget *widget = static_cast<QWidget *>(const_cast<QPaintDevice *>(device));
8363  widget->d_func()->setRedirected(redirectionDevice.replacement, redirectionDevice.offset);
8364  redirections->removeAt(internalWidgetRedirectionIndex);
8365  }
8366  return;
8367  }
8368  }
8369 }
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
QPointer< QWidget > widget
QPaintDevice * replacement
Definition: qpainter.cpp:8255
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ rotate()

void QPainter::rotate ( qreal  angle)

Rotates the coordinate system the given angle clockwise.

See also
setWorldTransform(), {QPainter::Coordinate Transformations}{Coordinate Transformations}

Definition at line 3287 of file qpainter.cpp.

Referenced by QCommonStyle::drawControl(), QWindowsVistaStyle::drawControl(), QWindowsMobileStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), and QMacStyle::standardIconImplementation().

3288 {
3289 #ifdef QT_DEBUG_DRAW
3290  if (qt_show_painter_debug_output)
3291  printf("QPainter::rotate(), angle=%f\n", a);
3292 #endif
3293  Q_D(QPainter);
3294  if (!d->engine) {
3295  qWarning("QPainter::rotate: Painter not active");
3296  return;
3297  }
3298 
3299  d->state->worldMatrix.rotate(a);
3300  d->state->WxF = true;
3301  d->updateMatrix();
3302 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ save()

void QPainter::save ( )

Saves the current painter state (pushes the state onto a stack).

A save() must be followed by a corresponding restore(); the end() function unwinds the stack.

See also
restore()

Definition at line 1590 of file qpainter.cpp.

Referenced by _q_paintItem(), QPainterPrivate::attachPainterPrivate(), QPaintBufferEngine::begin(), QFontEngineBox::boundingBox(), QSvgFont::draw(), QSvgTinyDocument::draw(), QTextLayout::draw(), QGraphicsScenePrivate::draw(), QTextLine::draw(), QGraphicsOpacityEffect::draw(), QGraphicsScene::drawBackground(), QWindowsXPStylePrivate::drawBackground(), QRenderRule::drawBackgroundImage(), QTextDocumentLayoutPrivate::drawBorder(), QPaintEnginePrivate::drawBoxTextItem(), QWindowsVistaStyle::drawComplexControl(), QWindowsCEStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QStyleSheetStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QSplashScreen::drawContents(), QDeclarativeTextInput::drawContents(), QTextDocument::drawContents(), QTextControl::drawContents(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QCDEStyle::drawControl(), QWindowsMobileStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QStyleHelper::drawDial(), QItemDelegate::drawDisplay(), QGraphicsScene::drawForeground(), QTextDocumentLayoutPrivate::drawFrameDecoration(), QX11PaintEngine::drawFreetype(), drawImage(), QTextDocumentLayoutPrivate::drawListItem(), QPlastiqueStylePrivate::drawPartialFrame(), drawPicture(), drawPixmap(), QPaintEngine::drawPoints(), drawPoints(), QWindowsCEStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QTreeView::drawRow(), QWindowsMobileStylePrivate::drawTabBarTab(), QPaintEngine::drawTextItem(), drawTextItemDecoration(), drawTiledPixmap(), QWidgetPrivate::drawWidget(), QPicture::exec(), fillBackground(), fillRegion(), QAlphaPaintEngine::flushAndInit(), QDecorationStyled::paint(), ShaderEffectItem::paint(), QItemDelegate::paint(), QDeclarativeImage::paint(), QFontFamilyDelegate::paint(), QDeclarativeText::paint(), QGraphicsTextItem::paint(), QCommandLinkButton::paintEvent(), QLabel::paintEvent(), QListView::paintEvent(), QHeaderView::paintEvent(), QGraphicsView::paintEvent(), QStaticTextPrivate::paintText(), QGraphicsWidget::paintWindowFrame(), printPage(), QPainterReplayer::process(), qDrawEdge(), qDrawRoundedCorners(), qt_format_text(), QGraphicsScene::render(), QGraphicsView::render(), QRenderRule::setClip(), setClip(), and QCommonStylePrivate::viewItemDrawText().

1591 {
1592 #ifdef QT_DEBUG_DRAW
1593  if (qt_show_painter_debug_output)
1594  printf("QPainter::save()\n");
1595 #endif
1596  Q_D(QPainter);
1597  if (!d->engine) {
1598  qWarning("QPainter::save: Painter not active");
1599  return;
1600  }
1601 
1602  if (d->extended) {
1603  d->state = d->extended->createState(d->states.back());
1604  d->extended->setState(d->state);
1605  } else {
1606  d->updateState(d->state);
1607  d->state = new QPainterState(d->states.back());
1608  d->engine->state = d->state;
1609  }
1610  d->states.push_back(d->state);
1611 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ scale()

void QPainter::scale ( qreal  sx,
qreal  sy 
)

Scales the coordinate system by ({sx}, {sy}).

See also
setWorldTransform() {QPainter::Coordinate Transformations}{Coordinate Transformations}

Definition at line 3234 of file qpainter.cpp.

Referenced by QGraphicsItem::boundingRegion(), QSvgFont::draw(), QSvgText::draw(), drawImage(), drawPixmap(), QSvgTinyDocument::mapSourceToTarget(), QDeclarativePaintedItem::paint(), QLabel::paintEvent(), qt_blurImage(), qt_format_text(), and ShaderEffect::updateRenderTargets().

3235 {
3236 #ifdef QT_DEBUG_DRAW
3237  if (qt_show_painter_debug_output)
3238  printf("QPainter::scale(), sx=%f, sy=%f\n", sx, sy);
3239 #endif
3240  Q_D(QPainter);
3241  if (!d->engine) {
3242  qWarning("QPainter::scale: Painter not active");
3243  return;
3244  }
3245 
3246  d->state->worldMatrix.scale(sx,sy);
3247  d->state->WxF = true;
3248  d->updateMatrix();
3249 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setBackground()

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).

See also
background(), setBackgroundMode(), {QPainter::Settings}{Settings}

Definition at line 4258 of file qpainter.cpp.

Referenced by QPainterPrivate::draw_helper(), QWindowsCEStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QPicture::exec(), and QAlphaPaintEnginePrivate::resetState().

4259 {
4260 #ifdef QT_DEBUG_DRAW
4261  if (qt_show_painter_debug_output)
4262  printf("QPainter::setBackground(), color=%04x, style=%d\n", bg.color().rgb(), bg.style());
4263 #endif
4264 
4265  Q_D(QPainter);
4266  if (!d->engine) {
4267  qWarning("QPainter::setBackground: Painter not active");
4268  return;
4269  }
4270  d->state->bgBrush = bg;
4271  if (!d->extended)
4272  d->state->dirtyFlags |= QPaintEngine::DirtyBackground;
4273 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setBackgroundMode()

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.

Note that in order to draw a bitmap or pixmap transparently, you must use QPixmap::setMask().

See also
backgroundMode(), setBackground(), {QPainter::Settings}{Settings}

Definition at line 3998 of file qpainter.cpp.

Referenced by QPainterPrivate::draw_helper(), QWindowsCEStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), drawImage(), drawPixmap(), QWindowsMobileStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), drawTiledPixmap(), QPicture::exec(), and QPainterReplayer::process().

3999 {
4000 #ifdef QT_DEBUG_DRAW
4001  if (qt_show_painter_debug_output)
4002  printf("QPainter::setBackgroundMode(), mode=%d\n", mode);
4003 #endif
4004 
4005  Q_D(QPainter);
4006  if (!d->engine) {
4007  qWarning("QPainter::setBackgroundMode: Painter not active");
4008  return;
4009  }
4010  if (d->state->bgMode == mode)
4011  return;
4012 
4013  d->state->bgMode = mode;
4014  if (d->extended) {
4015  d->checkEmulation();
4016  } else {
4017  d->state->dirtyFlags |= QPaintEngine::DirtyBackgroundMode;
4018  }
4019 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setBrush() [1/2]

void QPainter::setBrush ( const QBrush brush)

Sets the painter's brush to the given brush.

The painter's brush defines how shapes are filled.

See also
brush(), {QPainter::Settings}{Settings}

Definition at line 4171 of file qpainter.cpp.

Referenced by QFontEngine::alphaMapForGlyph(), alphaMapFromPath(), QSvgFillStyle::apply(), QSvgViewportFillStyle::apply(), QSvgAnimateColor::apply(), QBalloonTip::balloon(), QFontEngineBox::boundingBox(), QmlJSDebugger::ToolBarColorBox::createDragPixmap(), QSvgTinyDocument::draw(), QTextLayout::draw(), QGraphicsScenePrivate::draw(), QTextLine::draw(), QPainterPrivate::draw_helper(), QTextDocumentLayoutPrivate::drawBorder(), QPaintEnginePrivate::drawBoxTextItem(), QCommonStyle::drawComplexControl(), QWindowsCEStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleHelper::drawDial(), QTextDocumentLayoutPrivate::drawFrameDecoration(), QX11PaintEngine::drawFreetype(), drawImage(), QTextDocumentLayoutPrivate::drawListItem(), drawPixmap(), QPaintEngine::drawPoints(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QDeclarativeRectangle::drawRect(), QLCDNumberPrivate::drawSegment(), drawTabCloseButton(), QTextDocumentLayoutPrivate::drawTableCell(), drawTextItemDecoration(), drawTiledPixmap(), QPicture::exec(), QVGPaintEngine::fill(), QOpenGLPaintEngine::fill(), fillPath(), QX11PaintEnginePrivate::fillPolygon_dev(), fillRect(), QDeclarativeRectangle::generateBorderedRect(), QDeclarativeRectangle::generateRoundedRect(), QFontFamilyDelegate::paint(), QGraphicsPathItem::paint(), QGraphicsRectItem::paint(), QGraphicsEllipseItem::paint(), QGraphicsPolygonItem::paint(), QGraphicsSimpleTextItem::paint(), QGraphicsItemGroup::paint(), QBlittablePixmapData::paintEngine(), QWhatsThat::paintEvent(), QColorLuminancePicker::paintEvent(), QPainterReplayer::process(), qDrawEdge(), qDrawPlainRect(), qDrawRoundedCorners(), qDrawShadeRect(), qt_graphicsItem_highlightSelected(), QAlphaPaintEnginePrivate::resetState(), QSvgFillStyle::revert(), QSvgViewportFillStyle::revert(), QSvgAnimateColor::revert(), QWidgetPrivate::setWindowOpacity_sys(), and strokePath().

4172 {
4173 #ifdef QT_DEBUG_DRAW
4174  if (qt_show_painter_debug_output)
4175  printf("QPainter::setBrush(), color=%04x, style=%d\n", brush.color().rgb(), brush.style());
4176 #endif
4177  Q_D(QPainter);
4178  if (!d->engine) {
4179  qWarning("QPainter::setBrush: Painter not active");
4180  return;
4181  }
4182 
4183  if (d->state->brush.d == brush.d)
4184  return;
4185 
4186  if (d->extended) {
4187  d->state->brush = brush;
4188  d->checkEmulation();
4189  d->extended->brushChanged();
4190  return;
4191  }
4192 
4193  d->state->brush = brush;
4194  d->state->dirtyFlags |= QPaintEngine::DirtyBrush;
4195 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ setBrush() [2/2]

void QPainter::setBrush ( Qt::BrushStyle  style)

Sets the painter's brush to black color and the specified style.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4208 of file qpainter.cpp.

4209 {
4210  Q_D(QPainter);
4211  if (!d->engine) {
4212  qWarning("QPainter::setBrush: Painter not active");
4213  return;
4214  }
4215  if (d->state->brush.style() == style &&
4216  (style == Qt::NoBrush
4217  || (style == Qt::SolidPattern && d->state->brush.color() == QColor(0, 0, 0))))
4218  return;
4219  d->state->brush = QBrush(Qt::black, style);
4220  if (d->extended)
4221  d->extended->brushChanged();
4222  else
4223  d->state->dirtyFlags |= QPaintEngine::DirtyBrush;
4224 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76

◆ setBrushOrigin() [1/3]

void QPainter::setBrushOrigin ( int  x,
int  y 
)
inline

◆ setBrushOrigin() [2/3]

void QPainter::setBrushOrigin ( const QPoint position)
inline

Sets the brush's origin to the given position.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 830 of file qpainter.h.

831 {
833 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825

◆ setBrushOrigin() [3/3]

void QPainter::setBrushOrigin ( const QPointF position)

Sets the brush origin to position.

The brush origin specifies the (0, 0) coordinate of the painter's brush.

Note that while the brushOrigin() was necessary to adopt the parent's background for a widget in Qt 3, this is no longer the case since the Qt 4 painter doesn't paint the background unless you explicitly tell it to do so by setting the widget's QWidget::autoFillBackground property to true.

See also
brushOrigin(), {QPainter::Settings}{Settings}

Definition at line 2198 of file qpainter.cpp.

2199 {
2200  Q_D(QPainter);
2201 #ifdef QT_DEBUG_DRAW
2202  if (qt_show_painter_debug_output)
2203  printf("QPainter::setBrushOrigin(), (%.2f,%.2f)\n", p.x(), p.y());
2204 #endif
2205 
2206  if (!d->engine) {
2207  qWarning("QPainter::setBrushOrigin: Painter not active");
2208  return;
2209  }
2210 
2211  d->state->brushOrigin = p;
2212 
2213  if (d->extended) {
2214  d->extended->brushOriginChanged();
2215  return;
2216  }
2217 
2218  d->state->dirtyFlags |= QPaintEngine::DirtyBrushOrigin;
2219 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setClipPath()

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.

Note that the clip path is specified in logical (painter) coordinates.

See also
clipPath(), clipRegion(), {QPainter::Clipping}{Clipping}

Definition at line 3365 of file qpainter.cpp.

Referenced by QTextLayout::draw(), QPicture::exec(), QPainterReplayer::process(), QGraphicsView::render(), QAlphaPaintEnginePrivate::resetState(), QRenderRule::setClip(), setClip(), and setClipRect().

3366 {
3367 #ifdef QT_DEBUG_DRAW
3368  if (qt_show_painter_debug_output) {
3369  QRectF b = path.boundingRect();
3370  printf("QPainter::setClipPath(), size=%d, op=%d, bounds=[%.2f,%.2f,%.2f,%.2f]\n",
3371  path.elementCount(), op, b.x(), b.y(), b.width(), b.height());
3372  }
3373 #endif
3374  Q_D(QPainter);
3375 
3376  if (!d->engine) {
3377  qWarning("QPainter::setClipPath: Painter not active");
3378  return;
3379  }
3380 
3381  if ((!d->state->clipEnabled && op != Qt::NoClip) || (d->state->clipOperation == Qt::NoClip && op == Qt::UniteClip))
3382  op = Qt::ReplaceClip;
3383 
3384  if (d->extended) {
3385  d->state->clipEnabled = true;
3386  d->extended->clip(path, op);
3387  if (op == Qt::NoClip || op == Qt::ReplaceClip)
3388  d->state->clipInfo.clear();
3389  d->state->clipInfo << QPainterClipInfo(path, op, d->state->matrix);
3390  d->state->clipOperation = op;
3391  return;
3392  }
3393 
3394  if (d->state->clipOperation == Qt::NoClip && op == Qt::IntersectClip)
3395  op = Qt::ReplaceClip;
3396 
3397  d->state->clipPath = path;
3398  d->state->clipOperation = op;
3399  if (op == Qt::NoClip || op == Qt::ReplaceClip)
3400  d->state->clipInfo.clear();
3401  d->state->clipInfo << QPainterClipInfo(path, op, d->state->matrix);
3402  d->state->clipEnabled = true;
3404  d->updateState(d->state);
3405 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
#define Q_D(Class)
Definition: qglobal.h:2482
QRectF boundingRect() const
Returns the bounding rectangle of this painter path as a rectangle with floating point precision...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
Q_CORE_EXPORT void qWarning(const char *,...)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ setClipping()

void QPainter::setClipping ( bool  enable)

Enables clipping if enable is true, or disables clipping if enable is false.

See also
hasClipping(), {QPainter::Clipping}{Clipping}

Definition at line 2517 of file qpainter.cpp.

Referenced by QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QWindowsMobileStyle::drawComplexControl(), QCDEStyle::drawControl(), QWindowsMobileStyle::drawControl(), QWindowsMobileStyle::drawPrimitive(), QPicture::exec(), make_widget_eventUPP(), printPage(), QPainterReplayer::process(), qDrawPlainRect(), and QAlphaPaintEnginePrivate::resetState().

2518 {
2519  Q_D(QPainter);
2520 #ifdef QT_DEBUG_DRAW
2521  if (qt_show_painter_debug_output)
2522  printf("QPainter::setClipping(), enable=%s, was=%s\n",
2523  enable ? "on" : "off",
2524  hasClipping() ? "on" : "off");
2525 #endif
2526  if (!d->engine) {
2527  qWarning("QPainter::setClipping: Painter not active, state will be reset by begin");
2528  return;
2529  }
2530 
2531  if (hasClipping() == enable)
2532  return;
2533 
2534  // we can't enable clipping if we don't have a clip
2535  if (enable
2536  && (d->state->clipInfo.isEmpty() || d->state->clipInfo.last().operation == Qt::NoClip))
2537  return;
2538  d->state->clipEnabled = enable;
2539 
2540  if (d->extended) {
2541  d->extended->clipEnabledChanged();
2542  return;
2543  }
2544 
2545  d->state->dirtyFlags |= QPaintEngine::DirtyClipEnabled;
2546  d->updateState(d->state);
2547 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool hasClipping() const
Returns true if clipping has been set; otherwise returns false.
Definition: qpainter.cpp:2499
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setClipRect() [1/3]

void QPainter::setClipRect ( const QRectF rectangle,
Qt::ClipOperation  operation = Qt::ReplaceClip 
)

Enables clipping, and sets the clip region to the given rectangle using the given clip operation.

The default operation is to replace the current clip rectangle.

Note that the clip rectangle is specified in logical (painter) coordinates.

See also
clipRegion(), setClipping(), {QPainter::Clipping}{Clipping}

Definition at line 2801 of file qpainter.cpp.

Referenced by QTextLine::draw(), QRenderRule::drawBackgroundImage(), QCleanlooksStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QTextDocument::drawContents(), QTextControl::drawContents(), QCommonStyle::drawControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QStyleSheetStyle::drawControl(), QItemDelegate::drawDisplay(), QPlastiqueStylePrivate::drawPartialFrame(), QWindowsXPStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QTreeView::drawRow(), QItemDelegate::paint(), QDeclarativeImage::paint(), QDeclarativePaintedItem::paint(), QDeclarativeText::paint(), QFocusFrame::paintEvent(), QMdiSubWindow::paintEvent(), QMenuBar::paintEvent(), QLabel::paintEvent(), QPagePreview::paintEvent(), QWhatsThat::paintEvent(), QMenu::paintEvent(), QLineEdit::paintEvent(), QPlainTextEdit::paintEvent(), QGraphicsWidget::paintWindowFrame(), printPage(), QPainterReplayer::process(), qDrawPlainRect(), qt_format_text(), QGraphicsScene::render(), QGraphicsView::render(), and setClip().

2802 {
2803  Q_D(QPainter);
2804 
2805  if (d->extended) {
2806  if ((!d->state->clipEnabled && op != Qt::NoClip) || (d->state->clipOperation == Qt::NoClip && op == Qt::UniteClip))
2807  op = Qt::ReplaceClip;
2808 
2809  if (!d->engine) {
2810  qWarning("QPainter::setClipRect: Painter not active");
2811  return;
2812  }
2813  qreal right = rect.x() + rect.width();
2814  qreal bottom = rect.y() + rect.height();
2815  qreal pts[] = { rect.x(), rect.y(),
2816  right, rect.y(),
2817  right, bottom,
2818  rect.x(), bottom };
2819  QVectorPath vp(pts, 4, 0, QVectorPath::RectangleHint);
2820  d->state->clipEnabled = true;
2821  d->extended->clip(vp, op);
2822  if (op == Qt::ReplaceClip || op == Qt::NoClip)
2823  d->state->clipInfo.clear();
2824  d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix);
2825  d->state->clipOperation = op;
2826  return;
2827  }
2828 
2829  if (qreal(int(rect.top())) == rect.top()
2830  && qreal(int(rect.bottom())) == rect.bottom()
2831  && qreal(int(rect.left())) == rect.left()
2832  && qreal(int(rect.right())) == rect.right())
2833  {
2834  setClipRect(rect.toRect(), op);
2835  return;
2836  }
2837 
2838  if (rect.isEmpty()) {
2839  setClipRegion(QRegion(), op);
2840  return;
2841  }
2842 
2843  QPainterPath path;
2844  path.addRect(rect);
2845  setClipPath(path, op);
2846 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_CORE_EXPORT void qWarning(const char *,...)
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
Definition: qpainter.cpp:2917
void setClipPath(const QPainterPath &path, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation...
Definition: qpainter.cpp:3365

◆ setClipRect() [2/3]

void QPainter::setClipRect ( const QRect rectangle,
Qt::ClipOperation  operation = Qt::ReplaceClip 
)

Enables clipping, and sets the clip region to the given rectangle using the given clip operation.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2858 of file qpainter.cpp.

2859 {
2860  Q_D(QPainter);
2861 
2862  if (!d->engine) {
2863  qWarning("QPainter::setClipRect: Painter not active");
2864  return;
2865  }
2866 
2867  if ((!d->state->clipEnabled && op != Qt::NoClip) || (d->state->clipOperation == Qt::NoClip && op == Qt::UniteClip))
2868  op = Qt::ReplaceClip;
2869 
2870  if (d->extended) {
2871  d->state->clipEnabled = true;
2872  d->extended->clip(rect, op);
2873  if (op == Qt::ReplaceClip || op == Qt::NoClip)
2874  d->state->clipInfo.clear();
2875  d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix);
2876  d->state->clipOperation = op;
2877  return;
2878  }
2879 
2880  if (d->state->clipOperation == Qt::NoClip && op == Qt::IntersectClip)
2881  op = Qt::ReplaceClip;
2882 
2883  d->state->clipRegion = rect;
2884  d->state->clipOperation = op;
2885  if (op == Qt::NoClip || op == Qt::ReplaceClip)
2886  d->state->clipInfo.clear();
2887  d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix);
2888  d->state->clipEnabled = true;
2890  d->updateState(d->state);
2891 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setClipRect() [3/3]

void QPainter::setClipRect ( int  x,
int  y,
int  w,
int  h,
Qt::ClipOperation  op = Qt::ReplaceClip 
)
inline

Enables clipping, and sets the clip region to the rectangle beginning at (x, y) with the given width and height.

Definition at line 769 of file qpainter.h.

770 {
771  setClipRect(QRect(x, y, w, h), op);
772 }
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ setClipRegion()

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.

Note that the clip region is given in logical coordinates.

See also
clipRegion(), setClipRect(), {QPainter::Clipping}{Clipping}

Definition at line 2917 of file qpainter.cpp.

Referenced by _q_paintIntoCache(), QTableViewPrivate::drawAndClipSpans(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QWindowsVistaStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QWindowsCEStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QStyleSheetStyle::drawComplexControl(), QCommonStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QWindowsVistaStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QWidgetPrivate::drawWidget(), QPicture::exec(), fillRegion(), QDecorationStyled::paint(), QDecorationWindows::paint(), QDecorationDefault::paint(), QWidgetPrivate::paintBackground(), QMenuBar::paintEvent(), QMenu::paintEvent(), QGraphicsView::paintEvent(), QGraphicsWidget::paintWindowFrame(), QPainterReplayer::process(), qt_mac_fill_background(), QAlphaPaintEnginePrivate::resetState(), setClipRect(), QWidgetBackingStore::showYellowThing(), and QWidget::update().

2918 {
2919  Q_D(QPainter);
2920 #ifdef QT_DEBUG_DRAW
2921  QRect rect = r.boundingRect();
2922  if (qt_show_painter_debug_output)
2923  printf("QPainter::setClipRegion(), size=%d, [%d,%d,%d,%d]\n",
2924  r.rects().size(), rect.x(), rect.y(), rect.width(), rect.height());
2925 #endif
2926  if (!d->engine) {
2927  qWarning("QPainter::setClipRegion: Painter not active");
2928  return;
2929  }
2930 
2931  if ((!d->state->clipEnabled && op != Qt::NoClip) || (d->state->clipOperation == Qt::NoClip && op == Qt::UniteClip))
2932  op = Qt::ReplaceClip;
2933 
2934  if (d->extended) {
2935  d->state->clipEnabled = true;
2936  d->extended->clip(r, op);
2937  if (op == Qt::NoClip || op == Qt::ReplaceClip)
2938  d->state->clipInfo.clear();
2939  d->state->clipInfo << QPainterClipInfo(r, op, d->state->matrix);
2940  d->state->clipOperation = op;
2941  return;
2942  }
2943 
2944  if (d->state->clipOperation == Qt::NoClip && op == Qt::IntersectClip)
2945  op = Qt::ReplaceClip;
2946 
2947  d->state->clipRegion = r;
2948  d->state->clipOperation = op;
2949  if (op == Qt::NoClip || op == Qt::ReplaceClip)
2950  d->state->clipInfo.clear();
2951  d->state->clipInfo << QPainterClipInfo(r, op, d->state->matrix);
2952  d->state->clipEnabled = true;
2954  d->updateState(d->state);
2955 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ setCompositionMode()

void QPainter::setCompositionMode ( CompositionMode  mode)

Sets the composition mode to the given mode.

Warning
Only a QPainter operating on a QImage fully supports all composition modes. The RasterOp modes are supported for X11 as described in compositionMode().
See also
compositionMode()

Definition at line 2422 of file qpainter.cpp.

Referenced by _q_paintIntoCache(), QSvgCompOpStyle::apply(), QXcbWindowSurface::beginPaint(), QXlibWindowSurface::beginPaint(), QRasterWindowSurface::beginPaint(), QWSMemorySurface::beginPaint(), QPixmapDropShadowFilter::draw(), QGraphicsOpacityEffect::draw(), QPainterPrivate::draw_helper(), QWindowsVistaStyle::drawControl(), QPicture::exec(), QImage::fill(), QCommonStyle::generatedIconPixmap(), QDecorationStyled::paint(), QDecorationDefault::paint(), QDeclarativePaintedItem::paint(), QWidgetPrivate::paintBackground(), QDecorationDefault::paintButton(), QBlittablePixmapData::paintEngine(), QSystemTrayIconSys::paintEvent(), QPainterReplayer::process(), QSvgCompOpStyle::revert(), QPixmap::scroll(), QItemDelegate::selected(), and ShaderEffect::updateRenderTargets().

2423 {
2424  Q_D(QPainter);
2425  if (!d->engine) {
2426  qWarning("QPainter::setCompositionMode: Painter not active");
2427  return;
2428  }
2429  if (d->state->composition_mode == mode)
2430  return;
2431  if (d->extended) {
2432  d->state->composition_mode = mode;
2433  d->extended->compositionModeChanged();
2434  return;
2435  }
2436 
2438  if (!d->engine->hasFeature(QPaintEngine::RasterOpModes)) {
2439  qWarning("QPainter::setCompositionMode: "
2440  "Raster operation modes not supported on device");
2441  return;
2442  }
2443  } else if (mode >= QPainter::CompositionMode_Plus) {
2444  if (!d->engine->hasFeature(QPaintEngine::BlendModes)) {
2445  qWarning("QPainter::setCompositionMode: "
2446  "Blend modes not supported on device");
2447  return;
2448  }
2449  } else if (!d->engine->hasFeature(QPaintEngine::PorterDuff)) {
2450  if (mode != CompositionMode_Source && mode != CompositionMode_SourceOver) {
2451  qWarning("QPainter::setCompositionMode: "
2452  "PorterDuff modes not supported on device");
2453  return;
2454  }
2455  }
2456 
2457  d->state->composition_mode = mode;
2458  d->state->dirtyFlags |= QPaintEngine::DirtyCompositionMode;
2459 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setFont()

void QPainter::setFont ( const QFont font)

Sets the painter's font to the given font.

This font is used by subsequent drawText() functions. The text color is the same as the pen color.

If you set a font that isn't available, Qt 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).

See also
font(), drawText(), {QPainter::Settings}{Settings}

Definition at line 4288 of file qpainter.cpp.

Referenced by QSvgFontStyle::apply(), QDragManager::drag(), QWindowsCEStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QDeclarativeTextPrivate::drawTextLayout(), QPicture::exec(), QStaticTextPrivate::init(), QFontFamilyDelegate::paint(), QGraphicsSimpleTextItem::paint(), QCommandLinkButton::paintEvent(), QMdiSubWindow::paintEvent(), QPagePreview::paintEvent(), QHeaderView::paintEvent(), QGraphicsWidget::paintWindowFrame(), printPage(), QPainterReplayer::process(), QWidgetBackingStore::removeDirtyWidget(), QAlphaPaintEnginePrivate::resetState(), QSvgFontStyle::revert(), and QCommonStylePrivate::viewItemDrawText().

4289 {
4290  Q_D(QPainter);
4291 
4292 #ifdef QT_DEBUG_DRAW
4293  if (qt_show_painter_debug_output)
4294  printf("QPainter::setFont(), family=%s, pointSize=%d\n", font.family().toLatin1().constData(), font.pointSize());
4295 #endif
4296 
4297  if (!d->engine) {
4298  qWarning("QPainter::setFont: Painter not active");
4299  return;
4300  }
4301 
4302  d->state->font = QFont(font.resolve(d->state->deviceFont), device());
4303  if (!d->extended)
4304  d->state->dirtyFlags |= QPaintEngine::DirtyFont;
4305 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QString family() const
Returns the requested font family name, i.e.
Definition: qfont.cpp:906
int pointSize() const
Returns the point size of the font.
Definition: qfont.cpp:981

◆ setLayoutDirection()

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.

See also
QTextOption::setTextDirection(), layoutDirection(), drawText(), {QPainter::Settings}{Settings}

Definition at line 8717 of file qpainter.cpp.

Referenced by _q_paintItem().

8718 {
8719  Q_D(QPainter);
8720  if (d->state)
8721  d->state->layoutDirection = direction;
8722 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::LayoutDirection direction

◆ setMatrix()

void QPainter::setMatrix ( const QMatrix matrix,
bool  combine = false 
)

Use setWorldTransform() instead.

See also
setWorldTransform()

Definition at line 3045 of file qpainter.cpp.

Referenced by QMacStyle::drawPrimitive(), and rotateTabPainter().

3046 {
3047  setWorldTransform(QTransform(matrix), combine);
3048 }
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setMatrixEnabled()

void QPainter::setMatrixEnabled ( bool  enable)

Use setWorldMatrixEnabled() instead.

See also
setWorldMatrixEnabled()

Definition at line 3209 of file qpainter.cpp.

Referenced by QPicture::exec().

3210 {
3211  setWorldMatrixEnabled(enable);
3212 }
void setWorldMatrixEnabled(bool enabled)
Enables transformations if enable is true, or disables transformations if enable is false...
Definition: qpainter.cpp:3157

◆ setOpacity()

void QPainter::setOpacity ( qreal  opacity)

Sets the opacity of the painter to opacity.

Since
4.2

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.

Definition at line 2139 of file qpainter.cpp.

Referenced by _q_paintItem(), QSvgOpacityStyle::apply(), QSvgArc::draw(), QSvgLine::draw(), QSvgPolyline::draw(), QPixmapColorizeFilter::draw(), QSvgText::draw(), QGraphicsScenePrivate::draw(), QGraphicsOpacityEffect::draw(), QPainterPrivate::draw_helper(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsScene::drawItems(), QGraphicsScenePrivate::drawSubtreeRecursive(), QPicture::exec(), QTriangulator< T >::ComplexToSimple::Event::operator<(), QGraphicsView::paintEvent(), QPainterReplayer::process(), QAlphaPaintEnginePrivate::resetState(), QSvgOpacityStyle::revert(), QHeaderViewPrivate::setupSectionIndicator(), toVGImageWithOpacity(), and toVGImageWithOpacitySubRect().

2140 {
2141  Q_D(QPainter);
2142 
2143  if (!d->engine) {
2144  qWarning("QPainter::setOpacity: Painter not active");
2145  return;
2146  }
2147 
2148  opacity = qMin(qreal(1), qMax(qreal(0), opacity));
2149 
2150  if (opacity == d->state->opacity)
2151  return;
2152 
2153  d->state->opacity = opacity;
2154 
2155  if (d->extended)
2156  d->extended->opacityChanged();
2157  else
2158  d->state->dirtyFlags |= QPaintEngine::DirtyOpacity;
2159 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
qreal opacity() const
Returns the opacity of the painter.
Definition: qpainter.cpp:2115
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setPen() [1/3]

void QPainter::setPen ( const QColor color)

Sets the painter's pen to have style Qt::SolidLine, width 0 and the specified color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4047 of file qpainter.cpp.

Referenced by QFontEngine::alphaMapForGlyph(), alphaMapFromPath(), QSvgStrokeStyle::apply(), QSvgAnimateColor::apply(), QBalloonTip::balloon(), QFontEngineXLFD::bitmapForGlyphs(), QFontEngineBox::boundingBox(), QmlJSDebugger::ToolBarColorBox::createDragPixmap(), QDragManager::drag(), QDeclarativeTextLayout::draw(), QSvgFont::draw(), QSvgTinyDocument::draw(), QSvgPolyline::draw(), QTextLayout::draw(), QGraphicsScenePrivate::draw(), QTextLine::draw(), QPainterPrivate::draw_helper(), QTextDocumentLayoutPrivate::drawBlock(), QTextDocumentLayoutPrivate::drawBorder(), QPaintEnginePrivate::drawBoxTextItem(), QWindowsCEStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QStyleSheetStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QSplashScreen::drawContents(), QDeclarativeTextInput::drawContents(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QStyleHelper::drawDial(), QItemDelegate::drawDisplay(), QTextDocumentLayoutPrivate::drawFrame(), QTextDocumentLayoutPrivate::drawFrameDecoration(), QX11PaintEngine::drawFreetype(), drawImage(), QWindowsCEStyle::drawItemText(), QCleanlooksStyle::drawItemText(), QStyle::drawItemText(), QTextDocumentLayoutPrivate::drawListItem(), QWindowsMobileStylePrivate::drawPanelItemViewSelected(), QPlastiqueStylePrivate::drawPartialFrame(), QOpenGLPaintEngine::drawPixmap(), drawPixmap(), QPaintEngine::drawPoints(), drawPoints(), QWindowsCEStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QDeclarativeRectangle::drawRect(), QLCDNumberPrivate::drawSegment(), drawStaticText(), QWindowsMobileStylePrivate::drawTabBarTab(), drawTabBase(), drawTabCloseButton(), QTextDocumentLayoutPrivate::drawTableCell(), drawTabShape(), drawTextItemDecoration(), QDeclarativeTextPrivate::drawTextLayout(), QOpenGLPaintEngine::drawTiledPixmap(), drawTiledPixmap(), QWindowsCEStylePrivate::drawWinCEShades(), QWindowsCEStylePrivate::drawWinCEShadesSunken(), QWindowsCEStylePrivate::drawWinShades(), QPicture::exec(), QScriptEdit::extraAreaPaintEvent(), fillPath(), QX11PaintEnginePrivate::fillPolygon_dev(), fillRect(), QDeclarativeRectangle::generateBorderedRect(), QDeclarativeRectangle::generateRoundedRect(), generateWavyPixmap(), QTriangulator< T >::ComplexToSimple::Event::operator<(), QDecorationWindows::paint(), QDecorationDefault::paint(), QFontFamilyDelegate::paint(), QGraphicsPathItem::paint(), QGraphicsRectItem::paint(), QGraphicsEllipseItem::paint(), QGraphicsPolygonItem::paint(), QGraphicsLineItem::paint(), QGraphicsSimpleTextItem::paint(), QWellArray::paintCellContents(), QStatusBar::paintEvent(), QTableView::paintEvent(), QPagePreview::paintEvent(), QWhatsThat::paintEvent(), QLineEdit::paintEvent(), QComboBox::paintEvent(), QWizardHeader::paintEvent(), QFileDialogComboBox::paintEvent(), QWizardAntiFlickerWidget::paintEvent(), QColorPicker::paintEvent(), QColorLuminancePicker::paintEvent(), QPainterReplayer::process(), qDrawEdge(), qDrawPlainRect(), qDrawRoundedCorners(), qDrawShadeLine(), qDrawShadePanel(), qDrawShadeRect(), qDrawWinShades(), qt_cleanlooks_draw_mdibutton(), qt_graphicsItem_highlightSelected(), qt_plastique_draw_frame(), qt_plastique_draw_mdibutton(), qt_plastique_drawFrame(), qt_plastique_drawShadedPanel(), QAlphaPaintEnginePrivate::resetState(), QSvgStrokeStyle::revert(), QSvgAnimateColor::revert(), setPenAndDrawBackground(), QWidgetPrivate::setWindowOpacity_sys(), strokePath(), and QSvgNode::transformedBounds().

4048 {
4049 #ifdef QT_DEBUG_DRAW
4050  if (qt_show_painter_debug_output)
4051  printf("QPainter::setPen(), color=%04x\n", color.rgb());
4052 #endif
4053  Q_D(QPainter);
4054  if (!d->engine) {
4055  qWarning("QPainter::setPen: Painter not active");
4056  return;
4057  }
4058 
4059  if (d->state->pen.style() == Qt::SolidLine
4060  && d->state->pen.widthF() == 0
4061  && d->state->pen.isSolid()
4062  && d->state->pen.color() == color)
4063  return;
4064 
4065  QPen pen(color.isValid() ? color : QColor(Qt::black), 0, Qt::SolidLine);
4066 
4067  d->state->pen = pen;
4068  if (d->extended)
4069  d->extended->penChanged();
4070  else
4071  d->state->dirtyFlags |= QPaintEngine::DirtyPen;
4072 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
Q_CORE_EXPORT void qWarning(const char *,...)
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ setPen() [2/3]

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.

See also
pen(), {QPainter::Settings}{Settings}

Definition at line 4083 of file qpainter.cpp.

4084 {
4085 
4086 #ifdef QT_DEBUG_DRAW
4087  if (qt_show_painter_debug_output)
4088  printf("QPainter::setPen(), color=%04x, (brushStyle=%d) style=%d, cap=%d, join=%d\n",
4089  pen.color().rgb(), pen.brush().style(), pen.style(), pen.capStyle(), pen.joinStyle());
4090 #endif
4091  Q_D(QPainter);
4092  if (!d->engine) {
4093  qWarning("QPainter::setPen: Painter not active");
4094  return;
4095  }
4096 
4097  if (d->state->pen == pen)
4098  return;
4099 
4100  d->state->pen = pen;
4101 
4102  if (d->extended) {
4103  d->checkEmulation();
4104  d->extended->penChanged();
4105  return;
4106  }
4107 
4108  d->state->dirtyFlags |= QPaintEngine::DirtyPen;
4109 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
#define Q_D(Class)
Definition: qglobal.h:2482
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
Qt::PenJoinStyle joinStyle() const
Returns the pen&#39;s join style.
Definition: qpen.cpp:736
Q_CORE_EXPORT void qWarning(const char *,...)
QBrush brush() const
Returns the brush used to fill strokes generated with this pen.
Definition: qpen.cpp:797
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
Qt::PenCapStyle capStyle() const
Returns the pen&#39;s cap style.
Definition: qpen.cpp:706
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ setPen() [3/3]

void QPainter::setPen ( Qt::PenStyle  style)

Sets the painter's pen to have the given style, width 0 and black color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4121 of file qpainter.cpp.

4122 {
4123  Q_D(QPainter);
4124  if (!d->engine) {
4125  qWarning("QPainter::setPen: Painter not active");
4126  return;
4127  }
4128 
4129  if (d->state->pen.style() == style
4130  && (style == Qt::NoPen || (d->state->pen.widthF() == 0
4131  && d->state->pen.isSolid()
4132  && d->state->pen.color() == QColor(Qt::black))))
4133  return;
4134 
4135  // QPen(Qt::NoPen) is to avoid creating QPenData, including its brush (from the color)
4136  // Note that this works well as long as QPen(Qt::NoPen) returns a black, zero-width pen
4137  d->state->pen = (style == Qt::NoPen) ? QPen(Qt::NoPen) : QPen(Qt::black, 0, style);
4138 
4139  if (d->extended)
4140  d->extended->penChanged();
4141  else
4142  d->state->dirtyFlags |= QPaintEngine::DirtyPen;
4143 
4144 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setRedirected()

void QPainter::setRedirected ( const QPaintDevice device,
QPaintDevice replacement,
const QPoint offset = QPoint() 
)
static

Please use QWidget::render() instead.

Note
This class or function is threadsafe.

Redirects all paint commands for the given paint device, to the replacement device. The optional point offset 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.

Warning
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.
See also
redirected(), restoreRedirected()

Definition at line 8293 of file qpainter.cpp.

8296 {
8297  Q_ASSERT(device != 0);
8298 
8299  bool hadInternalWidgetRedirection = false;
8300  if (device->devType() == QInternal::Widget) {
8301  const QWidgetPrivate *widgetPrivate = static_cast<const QWidget *>(device)->d_func();
8302  // This is the case when the widget is in a paint event.
8303  if (widgetPrivate->redirectDev) {
8304  // Remove internal redirection and put it back into the global redirection list.
8305  QPoint oldOffset;
8306  QPaintDevice *oldReplacement = widgetPrivate->redirected(&oldOffset);
8307  const_cast<QWidgetPrivate *>(widgetPrivate)->restoreRedirected();
8308  setRedirected(device, oldReplacement, oldOffset);
8309  hadInternalWidgetRedirection = true;
8310  }
8311  }
8312 
8313  QPoint roffset;
8314  QPaintDevice *rdev = redirected(replacement, &roffset);
8315 
8316  QMutexLocker locker(globalRedirectionsMutex());
8317  QPaintDeviceRedirectionList *redirections = globalRedirections();
8318  Q_ASSERT(redirections != 0);
8319  *redirections += QPaintDeviceRedirection(device, rdev ? rdev : replacement, offset + roffset,
8320  hadInternalWidgetRedirection ? redirections->size() - 1 : -1);
8321  globalRedirectionAtomic()->ref();
8322 }
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
QPaintDevice * redirected(QPoint *offset) const
Definition: qwidget_p.h:628
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual int devType() const
Definition: qpaintdevice.h:167
QPaintDevice * redirectDev
Definition: qwidget_p.h:706
static void restoreRedirected(const QPaintDevice *device)
Using QWidget::render() obsoletes the use of this function.
Definition: qpainter.cpp:8344
static void setRedirected(const QPaintDevice *device, QPaintDevice *replacement, const QPoint &offset=QPoint())
Please use QWidget::render() instead.
Definition: qpainter.cpp:8293
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QPaintDevice * redirected(const QPaintDevice *device, QPoint *offset=0)
Using QWidget::render() obsoletes the use of this function.
Definition: qpainter.cpp:8391
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setRenderHint()

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.

See also
setRenderHints(), renderHints(), {QPainter::Rendering Quality}{Rendering Quality}

Definition at line 7620 of file qpainter.cpp.

Referenced by QFontEngine::alphaMapForGlyph(), alphaMapFromPath(), QSvgTinyDocument::draw(), QTextLine::draw(), QPainterPrivate::draw_helper(), QRenderRule::drawBackground(), QTextDocumentLayoutPrivate::drawBorder(), QRenderRule::drawBorder(), QRenderRule::drawBorderImage(), QCommonStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QDeclarativeTextInput::drawContents(), QDeclarativeTextEdit::drawContents(), QCommonStyle::drawControl(), QCleanlooksStyle::drawControl(), QMacStyle::drawControl(), QTextLayout::drawCursor(), QStyleHelper::drawDial(), drawImage(), QTextDocumentLayoutPrivate::drawListItem(), QRenderRule::drawOutline(), drawPixmap(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QDeclarativeRectangle::drawRect(), drawTabShape(), QPaintEngine::drawTextItem(), drawTextItem(), drawTiledPixmap(), QPicture::exec(), QScriptEdit::extraAreaPaintEvent(), QDeclarativeRectangle::generateBorderedRect(), QDeclarativeRectangle::generateRoundedRect(), generateWavyPixmap(), QMacPixmapData::macCreatePixels(), QTriangulator< T >::ComplexToSimple::Event::operator<(), QDeclarativeImage::paint(), QDeclarativeBorderImage::paint(), QDeclarativeRectangle::paint(), QDeclarativeText::paint(), QGraphicsPixmapItem::paint(), QLCDNumber::paintEvent(), QGraphicsWidget::paintWindowFrame(), QPainterReplayer::process(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), qDrawBorderPixmap(), qt_blurImage(), and QImage::transformed().

7621 {
7622 #ifdef QT_DEBUG_DRAW
7623  if (qt_show_painter_debug_output)
7624  printf("QPainter::setRenderHint: hint=%x, %s\n", hint, on ? "on" : "off");
7625 #endif
7626 
7627 #ifndef QT_NO_DEBUG
7628  static const bool antialiasingDisabled = qgetenv("QT_NO_ANTIALIASING").toInt();
7629  if (hint == QPainter::Antialiasing && antialiasingDisabled)
7630  return;
7631 #endif
7632 
7633  setRenderHints(hint, on);
7634 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
void setRenderHints(RenderHints hints, bool on=true)
Sets the given render hints on the painter if on is true; otherwise clears the render hints...
Definition: qpainter.cpp:7649
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...

◆ setRenderHints()

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.

Since
4.2
See also
setRenderHint(), renderHints(), {QPainter::Rendering Quality}{Rendering Quality}

Definition at line 7649 of file qpainter.cpp.

Referenced by _q_paintIntoCache(), QGraphicsItem::boundingRegion(), QGraphicsOpacityEffect::draw(), QDeclarativeRectangle::drawRect(), drawTabCloseButton(), QGraphicsProxyWidget::paint(), QDeclarativeImage::paint(), QDeclarativeBorderImage::paint(), QDeclarativePaintedItem::paint(), QDeclarativeRectangle::paint(), QDeclarativeText::paint(), QGraphicsView::paintEvent(), QGraphicsItemEffectSourcePrivate::pixmap(), QWidgetPrivate::render_helper(), and setRenderHint().

7650 {
7651  Q_D(QPainter);
7652 
7653  if (!d->engine) {
7654  qWarning("QPainter::setRenderHint: Painter must be active to set rendering hints");
7655  return;
7656  }
7657 
7658  if (on)
7659  d->state->renderHints |= hints;
7660  else
7661  d->state->renderHints &= ~hints;
7662 
7663  if (d->extended)
7664  d->extended->renderHintsChanged();
7665  else
7666  d->state->dirtyFlags |= QPaintEngine::DirtyHints;
7667 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setTransform()

void QPainter::setTransform ( const QTransform transform,
bool  combine = false 
)

◆ setViewport() [1/2]

void QPainter::setViewport ( const QRect rectangle)

Sets the painter's viewport rectangle to the given rectangle, and enables view transformations.

The viewport rectangle is part of the view transformation. The viewport specifies the device coordinate system. Its sister, the window(), specifies the logical coordinate system.

The default viewport rectangle is the same as the device's rectangle.

See also
viewport(), viewTransformEnabled() {Coordinate System::Window-Viewport Conversion}{Window-Viewport Conversion}

Definition at line 7815 of file qpainter.cpp.

Referenced by QPicture::exec().

7816 {
7817 #ifdef QT_DEBUG_DRAW
7818  if (qt_show_painter_debug_output)
7819  printf("QPainter::setViewport(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height());
7820 #endif
7821 
7822  Q_D(QPainter);
7823 
7824  if (!d->engine) {
7825  qWarning("QPainter::setViewport: Painter not active");
7826  return;
7827  }
7828 
7829  d->state->vx = r.x();
7830  d->state->vy = r.y();
7831  d->state->vw = r.width();
7832  d->state->vh = r.height();
7833 
7834  d->state->VxF = true;
7835  d->updateMatrix();
7836 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setViewport() [2/2]

void QPainter::setViewport ( int  x,
int  y,
int  width,
int  height 
)
inline

Sets the painter's viewport rectangle to be the rectangle beginning at (x, y) with the given width and height.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 985 of file qpainter.h.

986 {
987  setViewport(QRect(x, y, w, h));
988 }
void setViewport(const QRect &viewport)
Sets the painter&#39;s viewport rectangle to the given rectangle, and enables view transformations.
Definition: qpainter.cpp:7815
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ setViewTransformEnabled()

void QPainter::setViewTransformEnabled ( bool  enable)

Enables view transformations if enable is true, or disables view transformations if enable is false.

See also
viewTransformEnabled(), {Coordinate System::Window-Viewport Conversion}{Window-Viewport Conversion}

Definition at line 7906 of file qpainter.cpp.

Referenced by QPicture::exec(), and QAlphaPaintEnginePrivate::resetState().

7907 {
7908 #ifdef QT_DEBUG_DRAW
7909  if (qt_show_painter_debug_output)
7910  printf("QPainter::setViewTransformEnabled(), enable=%d\n", enable);
7911 #endif
7912 
7913  Q_D(QPainter);
7914 
7915  if (!d->engine) {
7916  qWarning("QPainter::setViewTransformEnabled: Painter not active");
7917  return;
7918  }
7919 
7920  if (enable == d->state->VxF)
7921  return;
7922 
7923  d->state->VxF = enable;
7924  d->updateMatrix();
7925 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setWindow() [1/2]

void QPainter::setWindow ( const QRect rectangle)

Sets the painter's window to the given rectangle, and enables view transformations.

The window rectangle is part of the view transformation. The window specifies the logical coordinate system. Its sister, the viewport(), specifies the device coordinate system.

The default window rectangle is the same as the device's rectangle.

See also
window(), viewTransformEnabled(), {Coordinate System::Window-Viewport Conversion}{Window-Viewport Conversion}

Definition at line 7745 of file qpainter.cpp.

Referenced by QPicture::exec(), and QTriangulator< T >::ComplexToSimple::Event::operator<().

7746 {
7747 #ifdef QT_DEBUG_DRAW
7748  if (qt_show_painter_debug_output)
7749  printf("QPainter::setWindow(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height());
7750 #endif
7751 
7752  Q_D(QPainter);
7753 
7754  if (!d->engine) {
7755  qWarning("QPainter::setWindow: Painter not active");
7756  return;
7757  }
7758 
7759  d->state->wx = r.x();
7760  d->state->wy = r.y();
7761  d->state->ww = r.width();
7762  d->state->wh = r.height();
7763 
7764  d->state->VxF = true;
7765  d->updateMatrix();
7766 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setWindow() [2/2]

void QPainter::setWindow ( int  x,
int  y,
int  width,
int  height 
)
inline

Sets the painter's window to the rectangle beginning at (x, y) and the given width and height.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 990 of file qpainter.h.

991 {
992  setWindow(QRect(x, y, w, h));
993 }
void setWindow(const QRect &window)
Sets the painter&#39;s window to the given rectangle, and enables view transformations.
Definition: qpainter.cpp:7745
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ setWorldMatrix()

void QPainter::setWorldMatrix ( const QMatrix matrix,
bool  combine = false 
)

Sets the transformation matrix to matrix and enables transformations.

Since
4.2
Note
It is advisable to use setWorldTransform() instead of this function to preserve the properties of perspective transformations.

If combine is true, then 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 function 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 functions can transform the coordinate system without using a QMatrix:

They operate on the painter's worldMatrix() and are implemented like this:

{
matrix.rotate(angle);
setWorldMatrix(matrix, true);
}

Note that when using setWorldMatrix() function you should always have combine be true when you are drawing into a QPicture. Otherwise it may not be possible to replay the picture with additional transformations; using the translate(), scale(), etc. convenience functions is safe.

For more information about the coordinate system, transformations and window-viewport conversion, see Coordinate System.

See also
setWorldTransform(), QTransform

Definition at line 3003 of file qpainter.cpp.

3004 {
3005  setWorldTransform(QTransform(matrix), combine);
3006 }
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setWorldMatrixEnabled()

void QPainter::setWorldMatrixEnabled ( bool  enable)

Enables transformations if enable is true, or disables transformations if enable is false.

Since
4.2

The world transformation matrix is not changed.

See also
worldMatrixEnabled(), worldTransform(), {QPainter::Coordinate Transformations}{Coordinate Transformations}

Definition at line 3157 of file qpainter.cpp.

Referenced by setMatrixEnabled().

3158 {
3159  Q_D(QPainter);
3160 #ifdef QT_DEBUG_DRAW
3161  if (qt_show_painter_debug_output)
3162  printf("QPainter::setMatrixEnabled(), enable=%d\n", enable);
3163 #endif
3164 
3165  if (!d->engine) {
3166  qWarning("QPainter::setMatrixEnabled: Painter not active");
3167  return;
3168  }
3169  if (enable == d->state->WxF)
3170  return;
3171 
3172  d->state->WxF = enable;
3173  d->updateMatrix();
3174 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setWorldTransform()

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.

See also
transform(), setTransform()

Definition at line 9630 of file qpainter.cpp.

Referenced by _q_paintIntoCache(), QSvgTransformStyle::apply(), QSvgAnimateTransform::apply(), QGraphicsItem::boundingRegion(), QGraphicsEffectSource::draw(), QGraphicsShaderEffect::draw(), QSvgTinyDocument::draw(), QPixmapBlurFilter::draw(), QGraphicsColorizeEffect::draw(), QSvgText::draw(), QGraphicsDropShadowEffect::draw(), QGraphicsOpacityEffect::draw(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsScene::drawItems(), QGraphicsScenePrivate::drawSubtreeRecursive(), QDeclarativeImage::paint(), QDeclarativeBorderImage::paint(), QGraphicsView::paintEvent(), ShaderEffect::prepareBufferedDraw(), QGraphicsScene::render(), QSvgTransformStyle::revert(), QSvgAnimateTransform::revert(), setMatrix(), setWorldMatrix(), setWorldTransform(), and QSvgNode::transformedBounds().

9631 {
9632  Q_D(QPainter);
9633 
9634  if (!d->engine) {
9635  qWarning("QPainter::setWorldTransform: Painter not active");
9636  return;
9637  }
9638 
9639  if (combine)
9640  d->state->worldMatrix = matrix * d->state->worldMatrix; // combines
9641  else
9642  d->state->worldMatrix = matrix; // set new matrix
9643 
9644  d->state->WxF = true;
9645  d->updateMatrix();
9646 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
const QMatrix & matrix() const
Use worldTransform() instead.
Definition: qpainter.cpp:3061
Q_CORE_EXPORT void qWarning(const char *,...)

◆ shear()

void QPainter::shear ( qreal  sh,
qreal  sv 
)

Shears the coordinate system by ({sh}, {sv}).

See also
setWorldTransform(), {QPainter::Coordinate Transformations}{Coordinate Transformations}

Definition at line 3258 of file qpainter.cpp.

3259 {
3260 #ifdef QT_DEBUG_DRAW
3261  if (qt_show_painter_debug_output)
3262  printf("QPainter::shear(), sh=%f, sv=%f\n", sh, sv);
3263 #endif
3264  Q_D(QPainter);
3265  if (!d->engine) {
3266  qWarning("QPainter::shear: Painter not active");
3267  return;
3268  }
3269 
3270  d->state->worldMatrix.shear(sh, sv);
3271  d->state->WxF = true;
3272  d->updateMatrix();
3273 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ strokePath()

void QPainter::strokePath ( const QPainterPath path,
const QPen pen 
)

Draws the outline (strokes) the path path with the pen specified by pen.

See also
fillPath(), {QPainter::Drawing}{Drawing}

Definition at line 3413 of file qpainter.cpp.

Referenced by drawArc(), QPicture::exec(), QPainterReplayer::process(), and setViewTransformEnabled().

3414 {
3415  Q_D(QPainter);
3416 
3417  if (!d->engine) {
3418  qWarning("QPainter::strokePath: Painter not active");
3419  return;
3420  }
3421 
3422  if (path.isEmpty())
3423  return;
3424 
3425  if (d->extended) {
3426  const QGradient *g = qpen_brush(pen).gradient();
3427  if (!g || g->coordinateMode() == QGradient::LogicalMode) {
3428  d->extended->stroke(qtVectorPathForPath(path), pen);
3429  return;
3430  }
3431  }
3432 
3433  QBrush oldBrush = d->state->brush;
3434  QPen oldPen = d->state->pen;
3435 
3436  setPen(pen);
3438 
3439  drawPath(path);
3440 
3441  // Reset old state
3442  setPen(oldPen);
3443  setBrush(oldBrush);
3444 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
const QVectorPath & qtVectorPathForPath(const QPainterPath &path)
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
QBrush qpen_brush(const QPen &p)
Definition: qpainter_p.h:87
Q_CORE_EXPORT void qWarning(const char *,...)
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047

◆ testRenderHint()

bool QPainter::testRenderHint ( RenderHint  hint) const
inline

Returns true if hint is set; otherwise returns false.

Since
4.3
See also
renderHints(), setRenderHint()

Definition at line 457 of file qpainter.h.

Referenced by QDeclarativeRectangle::drawRect(), QDeclarativeImage::paint(), QDeclarativeBorderImage::paint(), QDeclarativeRectangle::paint(), QDeclarativeText::paint(), and qDrawBorderPixmap().

457 { return renderHints() & hint; }
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675

◆ transform()

const QTransform & QPainter::transform ( ) const

◆ translate() [1/3]

void QPainter::translate ( const QPointF offset)

Translates the coordinate system by the given offset; i.e.

the given offset is added to points.

See also
setWorldTransform(), {QPainter::Coordinate Transformations}{Coordinate Transformations}

Definition at line 3311 of file qpainter.cpp.

Referenced by _q_paintIntoCache(), QGraphicsItem::boundingRegion(), QSvgUse::bounds(), QSvgFont::draw(), QPixmapBlurFilter::draw(), QSvgUse::draw(), QGraphicsOpacityEffect::draw(), QPainterPrivate::draw_helper(), QCommonStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QSplashScreen::drawContents(), QDeclarativeTextEdit::drawContents(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), drawImage(), drawPicture(), drawPixmap(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QMacStylePrivate::drawTableHeader(), drawTabShape(), QPaintEngine::drawTextItem(), drawTextItemDecoration(), QWidgetPrivate::drawWidget(), QPixmap::fill(), QX11PaintEnginePrivate::fillPolygon_dev(), generateWavyPixmap(), QSvgTinyDocument::mapSourceToTarget(), QTextEditPrivate::paint(), QDeclarativePaintedItem::paint(), QDeclarativeText::paint(), QGraphicsTextItem::paint(), QLCDNumber::paintEvent(), QLabel::paintEvent(), QWhatsThat::paintEvent(), QStaticTextPrivate::paintText(), QGraphicsWidget::paintWindowFrame(), printPage(), QPainterReplayer::process(), QTreeViewPrivate::renderTreeToPixmapForAnimation(), QMacStyle::standardIconImplementation(), and ShaderEffect::updateRenderTargets().

3312 {
3313  qreal dx = offset.x();
3314  qreal dy = offset.y();
3315 #ifdef QT_DEBUG_DRAW
3316  if (qt_show_painter_debug_output)
3317  printf("QPainter::translate(), dx=%f, dy=%f\n", dx, dy);
3318 #endif
3319  Q_D(QPainter);
3320  if (!d->engine) {
3321  qWarning("QPainter::translate: Painter not active");
3322  return;
3323  }
3324 
3325  d->state->worldMatrix.translate(dx, dy);
3326  d->state->WxF = true;
3327  d->updateMatrix();
3328 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
#define Q_D(Class)
Definition: qglobal.h:2482
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
Q_CORE_EXPORT void qWarning(const char *,...)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ translate() [2/3]

void QPainter::translate ( const QPoint offset)
inline

Translates the coordinate system by the given offset.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 980 of file qpainter.h.

981 {
982  translate(offset.x(), offset.y());
983 }
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ translate() [3/3]

void QPainter::translate ( qreal  dx,
qreal  dy 
)
inline

Translates the coordinate system by the vector (dx, dy).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 975 of file qpainter.h.

976 {
977  translate(QPointF(dx, dy));
978 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ viewport()

QRect QPainter::viewport ( ) const

Returns the viewport rectangle.

See also
setViewport(), setViewTransformEnabled()

Definition at line 7844 of file qpainter.cpp.

7845 {
7846  Q_D(const QPainter);
7847  if (!d->engine) {
7848  qWarning("QPainter::viewport: Painter not active");
7849  return QRect();
7850  }
7851  return QRect(d->state->vx, d->state->vy, d->state->vw, d->state->vh);
7852 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ viewTransformEnabled()

bool QPainter::viewTransformEnabled ( ) const

Returns true if view transformation is enabled; otherwise returns false.

See also
setViewTransformEnabled(), worldTransform()

Definition at line 7704 of file qpainter.cpp.

7705 {
7706  Q_D(const QPainter);
7707  if (!d->engine) {
7708  qWarning("QPainter::viewTransformEnabled: Painter not active");
7709  return false;
7710  }
7711  return d->state->VxF;
7712 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ window()

QRect QPainter::window ( ) const

Returns the window rectangle.

See also
setWindow(), setViewTransformEnabled()

Definition at line 7774 of file qpainter.cpp.

7775 {
7776  Q_D(const QPainter);
7777  if (!d->engine) {
7778  qWarning("QPainter::window: Painter not active");
7779  return QRect();
7780  }
7781  return QRect(d->state->wx, d->state->wy, d->state->ww, d->state->wh);
7782 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ worldMatrix()

const QMatrix & QPainter::worldMatrix ( ) const

Returns the world transformation matrix.

Since
4.2

It is advisable to use worldTransform() because worldMatrix() does not preserve the properties of perspective transformations.

See also
{QPainter::Coordinate Transformations}{Coordinate Transformations}, {Coordinate System}

Definition at line 3024 of file qpainter.cpp.

Referenced by matrix(), and qt_plastique_draw_gradient().

3025 {
3026  Q_D(const QPainter);
3027  if (!d->engine) {
3028  qWarning("QPainter::worldMatrix: Painter not active");
3029  return d->fakeState()->transform.toAffine();
3030  }
3031  return d->state->worldMatrix.toAffine();
3032 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ worldMatrixEnabled()

bool QPainter::worldMatrixEnabled ( ) const

Returns true if world transformation is enabled; otherwise returns false.

Since
4.2
See also
setWorldMatrixEnabled(), worldTransform(), {Coordinate System}

Definition at line 3188 of file qpainter.cpp.

Referenced by matrixEnabled().

3189 {
3190  Q_D(const QPainter);
3191  if (!d->engine) {
3192  qWarning("QPainter::worldMatrixEnabled: Painter not active");
3193  return false;
3194  }
3195  return d->state->WxF;
3196 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

◆ worldTransform()

const QTransform & QPainter::worldTransform ( ) const

Returns the world transformation matrix.

Definition at line 9652 of file qpainter.cpp.

Referenced by QSvgTransformStyle::apply(), QSvgAnimateTransform::apply(), QGraphicsEffectSource::draw(), QGraphicsShaderEffect::draw(), QSvgTinyDocument::draw(), QPixmapBlurFilter::draw(), QGraphicsColorizeEffect::draw(), QSvgText::draw(), QGraphicsDropShadowEffect::draw(), QGraphicsOpacityEffect::draw(), QGraphicsItemEffectSourcePrivate::draw(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsScene::drawItems(), QGraphicsScenePrivate::drawSubtreeRecursive(), QWidgetPrivate::drawWidget(), QGraphicsView::paintEvent(), ShaderEffect::prepareBufferedDraw(), and QWidgetPrivate::render_helper().

9653 {
9654  Q_D(const QPainter);
9655  if (!d->engine) {
9656  qWarning("QPainter::worldTransform: Painter not active");
9657  return d->fakeState()->transform;
9658  }
9659  return d->state->worldMatrix;
9660 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)

Friends and Related Functions

◆ Q3Painter

friend class Q3Painter
friend

Definition at line 544 of file qpainter.h.

◆ QAlphaPaintEngine

friend class QAlphaPaintEngine
friend

Definition at line 564 of file qpainter.h.

◆ QFontEngine

friend class QFontEngine
friend

Definition at line 548 of file qpainter.h.

◆ QFontEngineBox

friend class QFontEngineBox
friend

Definition at line 549 of file qpainter.h.

◆ QFontEngineFT

friend class QFontEngineFT
friend

Definition at line 550 of file qpainter.h.

◆ QFontEngineMac

friend class QFontEngineMac
friend

Definition at line 551 of file qpainter.h.

◆ QFontEngineWin

friend class QFontEngineWin
friend

Definition at line 552 of file qpainter.h.

◆ QFontEngineXLFD

friend class QFontEngineXLFD
friend

Definition at line 553 of file qpainter.h.

◆ QOpenGLPaintEngine

friend class QOpenGLPaintEngine
friend

Definition at line 557 of file qpainter.h.

◆ QPaintEngine

friend class QPaintEngine
friend

Definition at line 555 of file qpainter.h.

◆ QPaintEngineExPrivate

Definition at line 556 of file qpainter.h.

◆ QPreviewPaintEngine

friend class QPreviewPaintEngine
friend

Definition at line 565 of file qpainter.h.

◆ QRasterPaintEngine

friend class QRasterPaintEngine
friend

Definition at line 563 of file qpainter.h.

◆ QVGPaintEngine

friend class QVGPaintEngine
friend

Definition at line 558 of file qpainter.h.

◆ QWin32PaintEngine

friend class QWin32PaintEngine
friend

Definition at line 561 of file qpainter.h.

◆ QWin32PaintEnginePrivate

friend class QWin32PaintEnginePrivate
friend

Definition at line 562 of file qpainter.h.

◆ QWSManager

friend class QWSManager
friend

Definition at line 554 of file qpainter.h.

◆ QX11PaintEngine

friend class QX11PaintEngine
friend

Definition at line 559 of file qpainter.h.

◆ QX11PaintEnginePrivate

Definition at line 560 of file qpainter.h.

Properties

◆ d_ptr

QScopedPointer<QPainterPrivate> QPainter::d_ptr
private

The documentation for this class was generated from the following files: