QPainter(3qt)
π QPainter(3qt) π
okay bestie, this is part 1 of the QPainter(3qt) manual, and it's lowkey iconic. QPainter is the low-level painting class, fr fr. It inherits Qt, and QDirectPainter inherits from it. Let's get into the synopsis before I start crying over these signatures. π
β¨ NAME β¨
QPainter - Does low-level painting e.g. on widgets
πΈ SYNOPSIS πΈ
first, include the header, no cap:
#include <qpainter.h>
Inherits Qt.
Inherited by QDirectPainter.
π Public Members π
here's the whole public member roster. I'm not touching a single character of these signatures because that's the rule, and I respect the rule. π
enum CoordinateMode { CoordDevice, CoordPainter }
QPainter ()
QPainter ( const QPaintDevice * pd, bool unclipped = FALSE )
QPainter ( const QPaintDevice * pd, const QWidget * copyAttributes, bool
unclipped = FALSE )
~QPainter ()
bool begin ( const QPaintDevice * pd, bool unclipped = FALSE )
bool begin ( const QPaintDevice * pd, const QWidget * copyAttributes,
bool unclipped = FALSE )
bool end ()
QPaintDevice * device () const
bool isActive () const
void flush ( const QRegion & region, CoordinateMode cm = CoordDevice )
void flush ()
void save ()
void restore ()
QFontMetrics fontMetrics () const
QFontInfo fontInfo () const
const QFont & font () const
void setFont ( const QFont & font )
const QPen & pen () const
void setPen ( const QPen & pen )
void setPen ( PenStyle style )
void setPen ( const QColor & color )
const QBrush & brush () const
void setBrush ( const QBrush & brush )
void setBrush ( BrushStyle style )
void setBrush ( const QColor & color )
QPoint pos () const (obsolete)
const QColor & backgroundColor () const
void setBackgroundColor ( const QColor & c )
BGMode backgroundMode () const
void setBackgroundMode ( BGMode m )
RasterOp rasterOp () const
void setRasterOp ( RasterOp r )
const QPoint & brushOrigin () const
void setBrushOrigin ( int x, int y )
void setBrushOrigin ( const QPoint & p )
bool hasViewXForm () const
bool hasWorldXForm () const
void setViewXForm ( bool enable )
QRect window () const
void setWindow ( const QRect & r )
void setWindow ( int x, int y, int w, int h )
QRect viewport () const
void setViewport ( const QRect & r )
void setViewport ( int x, int y, int w, int h )
void setWorldXForm ( bool enable )
const QWMatrix & worldMatrix () const
void setWorldMatrix ( const QWMatrix & m, bool combine = FALSE )
void saveWorldMatrix () (obsolete)
void restoreWorldMatrix () (obsolete)
void scale ( double sx, double sy )
void shear ( double sh, double sv )
void rotate ( double a )
void translate ( double dx, double dy )
void resetXForm ()
QPoint xForm ( const QPoint & pv ) const
QRect xForm ( const QRect & rv ) const
QPointArray xForm ( const QPointArray & av ) const
QPointArray xForm ( const QPointArray & av, int index, int npoints )
const
QPoint xFormDev ( const QPoint & pd ) const
QRect xFormDev ( const QRect & rd ) const
QPointArray xFormDev ( const QPointArray & ad ) const
QPointArray xFormDev ( const QPointArray & ad, int index, int npoints )
const
void setClipping ( bool enable )
bool hasClipping () const
QRegion clipRegion ( CoordinateMode m = CoordDevice ) const
void setClipRect ( const QRect & r, CoordinateMode m = CoordDevice )
void setClipRect ( int x, int y, int w, int h, CoordinateMode m =
CoordDevice )
void setClipRegion ( const QRegion & rgn, CoordinateMode m = CoordDevice
)
void drawPoint ( int x, int y )
void drawPoint ( const QPoint & p )
void drawPoints ( const QPointArray & a, int index = 0, int npoints = -1
)
void moveTo ( int x, int y ) (obsolete)
void moveTo ( const QPoint & p ) (obsolete)
void lineTo ( int x, int y ) (obsolete)
void lineTo ( const QPoint & p ) (obsolete)
void drawLine ( int x1, int y1, int x2, int y2 )
void drawLine ( const QPoint & p1, const QPoint & p2 )
void drawRect ( int x, int y, int w, int h )
void drawRect ( const QRect & r )
void drawWinFocusRect ( int x, int y, int w, int h )
void drawWinFocusRect ( int x, int y, int w, int h, const QColor &
bgColor )
void drawWinFocusRect ( const QRect & r )
void drawWinFocusRect ( const QRect & r, const QColor & bgColor )
void drawRoundRect ( int x, int y, int w, int h, int xRnd = 25, int yRnd
= 25 )
void drawRoundRect ( const QRect & r, int xRnd = 25, int yRnd = 25 )
void drawEllipse ( int x, int y, int w, int h )
void drawEllipse ( const QRect & r )
void drawArc ( int x, int y, int w, int h, int a, int alen )
void drawArc ( const QRect & r, int a, int alen )
void drawPie ( int x, int y, int w, int h, int a, int alen )
void drawPie ( const QRect & r, int a, int alen )
void drawChord ( int x, int y, int w, int h, int a, int alen )
void drawChord ( const QRect & r, int a, int alen )
void drawLineSegments ( const QPointArray & a, int index = 0, int nlines
= -1 )
void drawPolyline ( const QPointArray & a, int index = 0, int npoints =
-1 )
void drawPolygon ( const QPointArray & a, bool winding = FALSE, int
index = 0, int npoints = -1 )
void drawConvexPolygon ( const QPointArray & pa, int index = 0, int
npoints = -1 )
void drawCubicBezier ( const QPointArray & a, int index = 0 )
void drawPixmap ( int x, int y, const QPixmap & pixmap, int sx = 0, int
sy = 0, int sw = -1, int sh = -1 )
void drawPixmap ( const QPoint & p, const QPixmap & pm, const QRect & sr
)
void drawPixmap ( const QPoint & p, const QPixmap & pm )
void drawPixmap ( const QRect & r, const QPixmap & pm )
void drawImage ( int x, int y, const QImage & image, int sx = 0, int sy
= 0, int sw = -1, int sh = -1, int conversionFlags = 0 )
void drawImage ( const QPoint &, const QImage &, const QRect & sr, int
conversionFlags = 0 )
void drawImage ( const QPoint & p, const QImage & i, int
conversion_flags = 0 )
void drawImage ( const QRect & r, const QImage & i )
void drawTiledPixmap ( int x, int y, int w, int h, const QPixmap &
pixmap, int sx = 0, int sy = 0 )
void drawTiledPixmap ( const QRect & r, const QPixmap & pm, const QPoint
& sp )
void drawTiledPixmap ( const QRect & r, const QPixmap & pm )
void drawPicture ( const QPicture & pic ) (obsolete)
void drawPicture ( int x, int y, const QPicture & pic )
void drawPicture ( const QPoint & p, const QPicture & pic )
void fillRect ( int x, int y, int w, int h, const QBrush & brush )
void fillRect ( const QRect & r, const QBrush & brush )
void eraseRect ( int x, int y, int w, int h )
void eraseRect ( const QRect & r )
enum TextDirection { Auto, RTL, LTR }
void drawText ( int x, int y, const QString &, int len = -1,
TextDirection dir = Auto )
void drawText ( const QPoint &, const QString &, int len = -1,
TextDirection dir = Auto )
void drawText ( int x, int y, const QString &, int pos, int len,
TextDirection dir = Auto )
void drawText ( const QPoint & p, const QString &, int pos, int len,
TextDirection dir = Auto )
void drawText ( int x, int y, int w, int h, int flags, const QString &,
int len = -1, QRect * br = 0, QTextParag ** internal = 0 )
void drawText ( const QRect & r, int tf, const QString & str, int len =
-1, QRect * brect = 0, QTextParag ** internal = 0 )
QRect boundingRect ( int x, int y, int w, int h, int flags, const
QString &, int len = -1, QTextParag ** intern = 0 )
QRect boundingRect ( const QRect & r, int flags, const QString & str,
int len = -1, QTextParag ** internal = 0 )
int tabStops () const
void setTabStops ( int ts )
int * tabArray () const
void setTabArray ( int * ta )
HDC handle () const
β¨ Static Public Members β¨
just one static bestie, and it's a redirect:
void redirect ( QPaintDevice * pdev, QPaintDevice * replacement )
π¦ RELATED FUNCTION DOCUMENTATION π¦
these are the related functions, and they're all about drawing shade and panels and buttons and plain rects. keep them exact, periodt.
void qDrawShadeLine ( QPainter * p, int x1, int y1, int x2, int y2,
const QColorGroup & g, bool sunken, int lineWidth, int midLineWidth
)
void qDrawShadeRect ( QPainter * p, int x, int y, int w, int h, const
QColorGroup & g, bool sunken, int lineWidth, int midLineWidth, const
QBrush * fill )
void qDrawShadePanel ( QPainter * p, int x, int y, int w, int h, const
QColorGroup & g, bool sunken, int lineWidth, const QBrush * fill )
void qDrawWinButton ( QPainter * p, int x, int y, int w, int h, const
QColorGroup & g, bool sunken, const QBrush * fill )
void qDrawWinPanel ( QPainter * p, int x, int y, int w, int h, const
QColorGroup & g, bool sunken, const QBrush * fill )
void qDrawPlainRect ( QPainter * p, int x, int y, int w, int h, const
QColor & c, int lineWidth, const QBrush * fill )
π DESCRIPTION π
okay so bestie, QPainter is the class that does the low-level painting β like, literally painting on widgets and stuff. π¨
The painter hands you highly optimized functions so you can do most of the drawing that GUI programs need. QPainter can draw everything from the simplest little lines all the way 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. iconic behavior honestly. β¨
So the typical use of a painter is, in order:
- Construct a painter.
- Set a pen, a brush etc.
- Draw.
- Destroy the painter.
Mostly all of this happens inside a paint event. (fr fr β 99% of all QPainter use is in a reimplementation of QWidget::paintEvent(), and the painter is heavily optimized for exactly that use.) Here's one very simple example:
void SimpleExampleWidget::paintEvent()
{
QPainter paint( this );
paint.setPen( Qt::blue );
paint.drawText( rect(), AlignCenter, "The Text" );
}
Usage is simple, and there are so many settings you can use:
font()is the currently set font. If you set a font that isn't available, Qt finds a close match. In factfont()returns what you set usingsetFont()andfontInfo()returns the font actually being used (which may be the same). πbrush()is the currently set brush; the color or pattern that's used for filling e.g. circles.pen()is the currently set pen; the color or stipple that's used for drawing lines or boundaries.backgroundMode()isOpaqueorTransparent, i.e. whetherbackgroundColor()is used or not.backgroundColor()only applies whenbackgroundMode()isOpaqueandpen()is a stipple. In that case, it describes the color of the background pixels in the stipple.rasterOp()is how pixels drawn interact with the pixels already there.brushOrigin()is the origin of the tiled brushes, normally the origin of the window.viewport(),window(),worldMatrix()and many more make up the painter's coordinate transformation system. See The Coordinate System for an explanation of this, or see below for a very brief overview of the functions.hasClipping()is whether the painter clips at all. (The paint device clips, too.) If the painter clips, it clips toclipRegion().pos()is the current position, set bymoveTo()and used bylineTo().
ngl, some of these settings mirror settings in some paint devices, e.g. QWidget::font(). QPainter::begin() (or the QPainter constructor) copies these attributes from the paint device. Calling, for example, QWidget::setFont() doesn't take effect until the next time a painter begins painting on it. π«Ά
save() saves all of these settings on an internal stack, restore() pops them back.
The core functionality of QPainter is drawing, and there are functions to draw most primitives: drawPoint(), drawPoints(), drawLine(), drawRect(), drawWinFocusRect(), drawRoundRect(), drawEllipse(), drawArc(), drawPie(), drawChord(), drawLineSegments(), drawPolyline(), drawPolygon(), drawConvexPolygon() and drawCubicBezier(). All of these functions take integer coordinates β there are no floating-point versions since we want drawing to be as fast as possible. π¨
There are functions to draw pixmaps/images, namely drawPixmap(), drawImage() and drawTiledPixmap(). drawPixmap() and drawImage() produce the same result, except that drawPixmap() is faster on-screen and drawImage() faster and sometimes better on QPrinter and QPicture.
Text drawing is done using drawText(), and when you need fine-grained positioning, boundingRect() tells you where a given drawText() command would draw. π¦
There is a drawPicture() function that draws the contents of an entire QPicture using this painter. drawPicture() is the only function that disregards all the painter's settings: the QPicture has its own settings. (main character energy tbh.)
Normally, the QPainter operates on the device's own coordinate system (usually pixels), but QPainter has good support for coordinate transformation. See The Coordinate System for a more general overview and a simple example.
The most common functions used are scale(), rotate(), translate() and shear(), all of which operate on the worldMatrix(). setWorldMatrix() can replace or add to the currently set worldMatrix().
setViewport() sets the rectangle on which QPainter operates. The default is the entire device, which is usually fine, except on printers. setWindow() sets the coordinate system, that is, the rectangle that maps to viewport(). What's drawn inside the window() ends up being inside the viewport(). The window's default is the same as the viewport, and if you don't use the transformations, they are optimized away, gaining another little bit of speed. ποΈ
After all the coordinate transformation is done, QPainter can clip the drawing to an arbitrary rectangle or region. hasClipping() is TRUE if QPainter clips, and clipRegion() returns the clip region. You can set it using either setClipRegion() or setClipRect(). Note that the clipping can be slow. It's all system-dependent, but as a rule of thumb, you can assume that drawing speed is inversely proportional to the number of rectangles in the clip region. π
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().
QPainter also includes some less-used functions that are very useful on those occasions when they're needed. iykyk π
isActive()indicates whether the painter is active.begin()(and the most usual constructor) makes it active.end()(and the destructor) deactivates it. If the painter is active,device()returns the paint device on which the painter paints.- Sometimes it is desirable to make someone else paint on an unusual
QPaintDevice.QPaintersupports a static function to do this,redirect(). We recommend not using it, but for some hacks it's perfect. setTabStops()andsetTabArray()can change where the tab stops are, but these are very seldomly used.
β οΈ Warning: Note that QPainter does not attempt to work around coordinate limitations in the underlying window system. Some platforms may behave incorrectly with coordinates as small as +/-4000. π
See also QPaintDevice, QWidget, QPixmap, QPrinter, QPicture, Application Walkthrough, Coordinate System Overview, Graphics Classes, and Image Processing Classes.
β¨ Member Type Documentation β¨
π QPainter::CoordinateMode π
QPainter::CoordDeviceQPainter::CoordPainter
See also clipRegion().
πΈ QPainter::TextDirection πΈ
QPainter::AutoQPainter::RTLβ right to leftQPainter::LTRβ left to right
See also drawText().
π MEMBER FUNCTION DOCUMENTATION π
π QPainter::QPainter () π
Constructs a painter.
Notice that all painter settings (setPen, setBrush etc.) are reset to default values when begin() is called. π
See also begin() and end().
π¦ QPainter::QPainter ( const QPaintDevice * pd, bool unclipped = FALSE ) π¦
Constructs a painter that begins painting the paint device pd immediately. Depending on the underlying graphic system the painter will paint over children of the paintdevice if unclipped is TRUE.
This constructor is convenient for short-lived painters, e.g. in a paint event 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 * )
{
QPainter p;
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() and end().
π QPainter::QPainter ( const QPaintDevice * pd, const QWidget * copyAttributes, bool unclipped = FALSE ) π
Constructs a painter that begins painting the paint device pd immediately, with the default arguments taken from copyAttributes. The painter will paint over children of the paint device if unclipped is TRUE (although this is not supported on all platforms).
See also begin().
β QPainter::~QPainter () β
Destroys the painter.
π const QColor & QPainter::backgroundColor () const π
Returns the current background color.
See also setBackgroundColor() and QColor.
π BGMode QPainter::backgroundMode () const π
Returns the current background mode.
See also setBackgroundMode() and BGMode.
π bool QPainter::begin ( const QPaintDevice * pd, bool unclipped = FALSE ) π
Begins painting the paint device pd and returns TRUE if successful; otherwise returns FALSE. If unclipped is TRUE, the painting will not be clipped at the paint device's boundaries, (although this is not supported by all platforms).
The errors that can occur are serious problems, such as these:
p->begin( 0 ); // impossible - paint device cannot be 0
QPixmap pm( 0, 0 );
p->begin( pm ); // impossible - pm.isNull();
p->begin( myWidget );
p2->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. no cap.
See also end() and flush().
Examples:
bool QPainter::begin ( const QPaintDevice * pd, const QWidget * copyAttributes, bool unclipped = FALSE )
Okay so this one's an overloaded member function, provided for convenience, and it behaves essentially like the one above it π. Bestie, it's the same vibe, slightly different toppings.
This version opens the painter on a paint device pd and sets the initial pen, background color and font from copyAttributes, painting over the paint device's children when unclipped is TRUE. And it's literally the same as doing all this by hand:
QPainter p;
p.begin( pd );
p.setPen( copyAttributes->foregroundColor() );
p.setBackgroundColor( copyAttributes->backgroundColor() );
p.setFont( copyAttributes->font() );
This begin function is so convenient for double buffering. When you draw in a pixmap instead of directly in a widget (so you can later bitBlt the pixmap into the widget), you're gonna need to set the widget's font and all that. This function does exactly that. No cap π«Ά.
Example:
void MyWidget::paintEvent( QPaintEvent * )
{
QPixmap pm(size());
QPainter p;
p.begin(&pm, this);
// ... potentially flickering paint operation ...
p.end();
bitBlt(this, 0, 0, &pm);
}
See also end().
QRect QPainter::boundingRect ( int x, int y, int w, int h, int flags, const QString &, int len = -1, QTextParag ** intern = 0 )
Returns the bounding rectangle of the aligned text that would be printed with the corresponding drawText() function, using the first len characters of the string if len is > -1, or the whole of the string if len is -1. The drawing β and therefore the bounding rectangle β is constrained to the rectangle that begins at point (x, y) with width w and hight h, or to the rectangle required to draw the text, whichever is the larger π
.
The flags argument is the bitwise OR of the following flags: (the list lives in the Qt::TextFlags docs β it got mangled in the original markup, but the flags are the flags, bestie, go look π)
Horizontal alignment defaults to AlignLeft and vertical alignment defaults to AlignTop.
If several of the horizontal or several of the vertical alignment flags are set, the resulting alignment is undefined. So likeβ¦ don't do that π.
The intern parameter should not be used. Periodt.
See also Qt::TextFlags.
QRect QPainter::boundingRect ( const QRect & r, int flags, const QString & str, int len = -1, QTextParag ** internal = 0 )
Another overloaded member function, provided for convenience, behaving essentially like the one above it β¨.
Returns the bounding rectangle of the aligned text that would be printed with the corresponding drawText() function, using the first len characters from str if len is > -1, or the whole of str if len is -1. The drawing, and hence the bounding rectangle, is constrained to the rectangle r, or to the rectangle required to draw the text, whichever is the larger.
The internal parameter should not be used. (Same energy as intern up there β hands off π«)
See also drawText(), fontMetrics(), QFontMetrics::boundingRect(), and Qt::TextFlags.
const QBrush & QPainter::brush () const
Returns the painter's current brush ποΈ.
See also QPainter::setBrush().
Examples: yep, there are examples for this one π.
const QPoint & QPainter::brushOrigin () const
Returns the brush origin currently set.
See also setBrushOrigin().
QRegion QPainter::clipRegion ( CoordinateMode m = CoordDevice ) const
Returns the currently set clip region πΈ. Note that the clip region is given in physical device coordinates and is not subject to any coordinate transformation if m is equal to CoordDevice (that's the default). If m equals CoordPainter, the region you get back is in model coordinates.
See also setClipRegion(), setClipRect(), setClipping(), and QPainter::CoordinateMode.
Example: themes/wood.cpp.
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 QPaintDevice::paintingActive().
Examples: yes bestie, examples exist for this one too π .
void QPainter::drawArc ( int x, int y, int w, int h, int a, int alen )
Draws an arc defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.
The angles a and alen are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). Positive values of a and alen mean counter-clockwise, while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position π.
Example:
QPainter p( myWidget );
p.drawArc( 10,10, 70,100, 100*16, 160*16 ); // draws a "(" arc
See also drawPie() and drawChord().
void QPainter::drawArc ( const QRect & r, int a, int alen )
Overloaded member function, provided for convenience, behaves essentially like the above π.
Draws the arc that fits inside the rectangle r with start angle a and arc length alen.
void QPainter::drawChord ( int x, int y, int w, int h, int a, int alen )
Draws a chord defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.
The chord is filled with the current brush() π¨.
The angles a and alen are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). Positive values of a and alen mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.
See also drawArc() and drawPie().
void QPainter::drawChord ( const QRect & r, int a, int alen )
Overloaded member function, provided for convenience, behaves essentially like the above β¨.
Draws a chord that fits inside the rectangle r with start angle a and arc length alen.
void QPainter::drawConvexPolygon ( const QPointArray & pa, int index = 0, int npoints = -1 )
Draws the convex polygon defined by the npoints points in pa, starting at pa[index] (index defaults to 0).
If the supplied polygon is not convex, the results are undefined. Bestie. Convex only. I'm serious π.
On some platforms (e.g. X Window), this is faster than drawPolygon() π₯.
Warning: On X11, coordinates that do not fit into 16-bit signed values are truncated. This limitation is expected to go away in Qt 4.
Example: aclock/aclock.cpp.
void QPainter::drawCubicBezier ( const QPointArray & a, int index = 0 )
Draws a cubic Bezier curve defined by the control points in a, starting at a[index] (index defaults to 0).
Control points after a[index + 3] are ignored. Nothing happens if there aren't enough control points π.
Warning: On X11, coordinates that do not fit into 16-bit signed values are truncated. This limitation is expected to go away in Qt 4.
void QPainter::drawEllipse ( int x, int y, int w, int h )
Draws an ellipse with center at (x + w/2, y + h/2) and size (w, h) π₯.
Examples: there are examples, bestie π.
void QPainter::drawEllipse ( const QRect & r )
Overloaded member function, provided for convenience, behaves essentially like the above.
Draws the ellipse that fits inside rectangle r.
void QPainter::drawImage ( int x, int y, const QImage & image, int sx = 0, int sy = 0, int sw = -1, int sh = -1, int conversionFlags = 0 )
Draws at (x, y) the sw by sh area of pixels from (sx, sy) in image, using conversionFlags if the image needs to be converted to a pixmap. The default value for conversionFlags is 0; see convertFromImage() for info about what the other values do π.
This function may convert image to a pixmap and then draw it, if device() is a QPixmap or a QWidget, or else draw it directly, if device() is a QPrinter or QPicture.
Currently alpha masks of the image are ignored when painting on a QPrinter. Noted. Moving on π .
See also drawPixmap() and QPixmap::convertFromImage().
Example: canvas/canvas.cpp.
void QPainter::drawImage ( const QPoint &, const QImage &, const QRect & sr, int conversionFlags = 0 )
Overloaded member function, provided for convenience, behaves essentially like the above.
Draws the rectangle sr from the image at the given point.
void QPainter::drawImage ( const QPoint & p, const QImage & i, int conversion_flags = 0 )
Overloaded member function, provided for convenience, behaves essentially like the above β¨.
Draws the image i at point p.
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the conversion_flags to specify how you'd prefer this to happen.
See also Qt::ImageConversionFlags.
void QPainter::drawImage ( const QRect & r, const QImage & i )
Overloaded member function, provided for convenience, behaves essentially like the above.
Draws the image i into the rectangle r. The image will be scaled to fit the rectangle if image and rectangle dimensions differ π.
void QPainter::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) βοΈ.
See also pen().
Examples: yes, examples π.
void QPainter::drawLine ( const QPoint & p1, const QPoint & p2 )
Overloaded member function, provided for convenience, behaves essentially like the above.
Draws a line from point p1 to point p2.
void QPainter::drawLineSegments ( const QPointArray & a, int index = 0, int nlines = -1 )
Draws nlines separate lines from points defined in a, starting at a[index] (index defaults to 0). If nlines is -1 (the default), all points until the end of the array are used β i.e. (a.size()-index)/2 lines get drawn π
.
Draws the 1st line from a[index] to a[index+1]. Draws the 2nd line from a[index+2] to a[index+3], etc. Iconic, honestly.
Warning: On X11, coordinates that do not fit into 16-bit signed values are truncated. This limitation is expected to go away in Qt 4.
See also drawPolyline(), drawPolygon(), and QPen.
void QPainter::drawPicture ( int x, int y, const QPicture & pic )
Replays the picture pic translated by (x, y) π¬.
This function does exactly the same as QPicture::play() when called with (x, y) = (0, 0).
Examples: you know the drill, there are examples π«Ά.
void QPainter::drawPicture ( const QPicture & pic )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code. π«
Use one of the other QPainter::drawPicture() functions with a (0, 0) offset instead.
void QPainter::drawPicture ( const QPoint & p, const QPicture & pic )
Overloaded member function, provided for convenience, behaves essentially like the above β¨.
Draws picture pic at point p.
void QPainter::drawPie ( int x, int y, int w, int h, int a, int alen )
Draws a pie defined by the rectangle (x, y, w, h), the start angle a and the arc length alen π₯§.
The pie is filled with the current brush().
The angles a and alen are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). Positive values of a and alen mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position π.
See also drawArc() and drawChord().
Examples: yes bestie, there are examples π.
void QPainter::drawPie ( const QRect & r, int a, int alen )
okay this one's just the overloaded twin, provided for convenience β it behaves essentially like the one above, bestie π
It draws a pie segment that fits inside the rectangle r, with start angle a and arc length alen.
void QPainter::drawPixmap ( int x, int y, const QPixmap & pixmap, int sx = 0, int sy = 0, int sw = -1, int sh = -1 )
Draws a pixmap at (x, y) by copying a part of pixmap into the paint device. like, a lil slice of the pixmap, not the whole thing, slay β¨
(x, y)= the top-left point in the paint device that's getting drawn onto.(sx, sy)= the top-left point in the pixmap that's getting drawn. Default is(0, 0).(sw, sh)= the size of the pixmap that's drawn. Default is(-1, -1), which means all the way to the bottom-right of the pixmap. no cap, the whole thing π
heads up fr fr: currently the mask of the pixmap β or its alpha channel β are ignored when you're painting on a QPrinter. so that transparency? not showing up there, sorry bestie π
See also bitBlt() and QPixmap::setMask().
Examples:
void QPainter::drawPixmap ( const QPoint & p, const QPixmap & pm, const QRect & sr )
Another overloaded member function, provided for convenience. It behaves essentially like the above function.
Draws the rectangle sr of pixmap pm, with its origin at point p. π«
void QPainter::drawPixmap ( const QPoint & p, const QPixmap & pm )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws the pixmap pm with its origin at point p. simple as that πΈ
void QPainter::drawPixmap ( const QRect & r, const QPixmap & pm )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws the pixmap pm into the rectangle r. If the image and the rectangle sizes disagree, the pixmap gets scaled to fit the rectangle. it's giving stretch-to-fit energy π§
void QPainter::drawPoint ( int x, int y )
Draws/plots a single point at (x, y) using the current pen. one (1) point. that's the whole function. iconic minimalism β¨
See also QPen.
Examples:
void QPainter::drawPoint ( const QPoint & p )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws the point p. π
void QPainter::drawPoints ( const QPointArray & a, int index = 0, int npoints = -1 )
Draws/plots an array of points, a, using the current pen. it's the point function but make it a whole array π
- If
indexis non-zero (default is zero), only points fromindexget drawn. - If
npointsis negative (the default), the rest of the points fromindexget drawn. - If
npointsis zero or greater, exactlynpointspoints get drawn.
β οΈ WARNING: on X11, coordinates that don't fit into 16-bit signed values are truncated. this limitation is expected to go away in Qt 4. so if ur coords are huge, bestieβ¦ yeah. π
void QPainter::drawPolygon ( const QPointArray & a, bool winding = FALSE, int index = 0, int npoints = -1 )
Draws the polygon defined by the npoints points in a, starting at a[index]. (index defaults to 0.)
- If
npointsis-1(the default), all points until the end of the array are used β i.e.a.size()-indexline segments define the polygon. - The first point is always connected to the last point. always. it's the law π«Ά
The polygon is filled with the current brush(). If winding is TRUE, the polygon is filled using the winding fill algorithm. If winding is FALSE, it's filled using the even-odd (alternative) fill algorithm. two completely different vibes, pick wisely π
β οΈ WARNING: on X11, coordinates that don't fit into 16-bit signed values are truncated. this limitation is expected to go away in Qt 4.
See also drawLineSegments(), drawPolyline(), and QPen.
Examples:
void QPainter::drawPolyline ( const QPointArray & a, int index = 0, int npoints = -1 )
Draws the polyline defined by the npoints points in a, starting at a[index]. (index defaults to 0.)
- If
npointsis-1(the default), all points until the end of the array are used β i.e.a.size()-index-1line segments are drawn.
note the difference bestie: polygon connects the first point to the last, polyline does not.a.size()-index-1vsa.size()-index. the way i clocked that immediately π
β οΈ WARNING: on X11, coordinates that don't fit into 16-bit signed values are truncated. this limitation is expected to go away in Qt 4.
See also drawLineSegments(), drawPolygon(), and QPen.
Examples:
void QPainter::drawRect ( int x, int y, int w, int h )
Draws a rectangle with upper-left corner at (x, y), with width w and height h. a rectangle. that's it. that's the post πβ¨
See also QPen and drawRoundRect().
Examples:
void QPainter::drawRect ( const QRect & r )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws the rectangle r. π
void QPainter::drawRoundRect ( int x, int y, int w, int h, int xRnd = 25, int yRnd = 25 )
Draws a rectangle with rounded corners at (x, y), with width w and height h. soft edges, gentle energy, we love her πΈ
xRndandyRndspecify how rounded the corners should be.0is angled corners,99is maximum roundedness. so like,0= sharp lil gremlin,99= the softest bean π«Ά
The width and height include all of the drawn lines.
See also drawRect() and QPen.
Examples:
void QPainter::drawRoundRect ( const QRect & r, int xRnd = 25, int yRnd = 25 )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws a rounded rectangle r, rounding to the x position xRnd and the y position yRnd on each corner. every single corner. no corner left behind π
void QPainter::drawText ( const QPoint & p, const QString &, int pos, int len, TextDirection dir = Auto )
Draws the text from position pos, at point p. If len is -1 the entire string is drawn, otherwise just the first len characters. The text's direction is specified by dir. π¦
okay SUPER important bestie, do not skip this: the meaning ofyis not the same for the twodrawText()varieties. For overloads that take a simplex, ypair (or a point), theyvalue is the text's baseline. For overloads that take a rectangle,rect.y()is the top of the rectangle, and the text is aligned within that rectangle according to the alignment flags. two differentymeanings. ikyk π
See also QPainter::TextDirection.
Examples:
void QPainter::drawText ( int x, int y, const QString &, int len = -1, TextDirection dir = Auto )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws the given text at position x, y. If len is -1 (the default) all the text is drawn, otherwise the first len characters are drawn. The text's direction is given by dir.
See also QPainter::TextDirection.
void QPainter::drawText ( const QPoint &, const QString &, int len = -1, TextDirection dir = Auto )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws the text at the given point. π
See also QPainter::TextDirection.
void QPainter::drawText ( int x, int y, const QString &, int pos, int len, TextDirection dir = Auto )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws the text from position pos, at point (x, y). If len is -1 the entire string is drawn, otherwise just the first len characters. The text's direction is specified by dir. β¨
void QPainter::drawText ( int x, int y, int w, int h, int flags, const QString &, int len = -1, QRect * br = 0, QTextParag ** internal = 0 )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws the given text within the rectangle starting at x, y, with width w and height h. If len is -1 (the default) all the text is drawn, otherwise the first len characters are drawn. The text's flags given in the flags parameter are Qt::AlignmentFlags and Qt::TextFlags OR'd together. br (if it's not null) gets set to the actual bounding rectangle of the output. The internal parameter is for internal use only. π« don't touch it bestie, that's not for us.
void QPainter::drawText ( const QRect & r, int tf, const QString & str, int len = -1, QRect * brect = 0, QTextParag ** internal = 0 )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws at most len characters from str in the rectangle r. π
This function draws formatted text. The tf text format is really of type Qt::AlignmentFlags and Qt::TextFlags OR'd together.
- Horizontal alignment defaults to
AlignAuto. - Vertical alignment defaults to
AlignTop.
brect (if not null) gets set to the actual bounding rectangle of the output. internal is, yes, internal. π
See also boundingRect().
void QPainter::drawTiledPixmap ( int x, int y, int w, int h, const QPixmap & pixmap, int sx = 0, int sy = 0 )
Draws a tiled pixmap in the specified rectangle. like wallpaper but make it code π§β¨
(x, y)= the top-left point in the paint device that's getting drawn onto, with the width and height given bywandh.(sx, sy)= the top-left point inpixmapthat's getting drawn. Default is(0, 0).
Calling drawTiledPixmap() is similar to calling drawPixmap() several times to fill (tile) an area with a pixmap β but it's potentially much more efficient, depending on the underlying window system. so like, same look, way less work. ate. π₯
See also drawPixmap().
void QPainter::drawTiledPixmap ( const QRect & r, const QPixmap & pm, const QPoint & sp )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws a tiled pixmap, pm, inside rectangle r, with its origin at point sp. π«
void QPainter::drawTiledPixmap ( const QRect & r, const QPixmap & pm )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws a tiled pixmap, pm, inside rectangle r. π
void QPainter::drawWinFocusRect ( int x, int y, int w, int h, const QColor & bgColor )
Draws a Windows focus rectangle with upper-left corner at (x, y) and with width w and height h, using a pen color that contrasts with bgColor. π
This function draws a stippled rectangle (XOR is not used) that's used to indicate keyboard focus (when QApplication::style() is WindowStyle).
The pen color used to draw the rectangle is either white or black, depending on the color of bgColor (see QColor::gray()).
β οΈ WARNING: this function draws nothing if the coordinate system has been rotated or sheared. literally nothing. not a single pixel. π
See also drawRect() and QApplication::style().
void QPainter::drawWinFocusRect ( int x, int y, int w, int h )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws a Windows focus rectangle with upper-left corner at (x, y) and with width w and height h.
This function draws a stippled XOR rectangle that's used to indicate keyboard focus (when QApplication::style() is WindowStyle). π
β οΈ WARNING: this function draws nothing if the coordinate system has been rotated or sheared.
See also drawRect() and QApplication::style().
void QPainter::drawWinFocusRect ( const QRect & r )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws rectangle r as a window focus rectangle. β¨
void QPainter::drawWinFocusRect ( const QRect & r, const QColor & bgColor )
Overloaded member function, provided for convenience. Behaves essentially like the above function.
Draws rectangle r as a window focus rectangle using background color bgColor. π
β¨ QPainter::end () β¨
bool QPainter::end ()
Bestie, this one ends the painting. Everything the painter was using gets released, like closing the group chat when the convo dies. π
Okay so important tea: most of the time you don't have to call end() at all β the destructor handles it for you, she's responsible like that. BUT there's one super common case where you absolutely need it, and that's double buffering:
QPainter p( myPixmap, this )
// ...
p.end(); // stops drawing on myPixmap
p.begin( this );
p.drawPixmap( 0, 0, myPixmap );
The reason is lowkey so real: you can't draw a QPixmap while it's actively being painted on, so you have to close the active painter first. Periodt.
See also begin() and isActive().
Examples:
π§½ QPainter::eraseRect ( int x, int y, int w, int h ) π§½
void QPainter::eraseRect ( int x, int y, int w, int h )
Erases whatever's inside x, y, w, h. It's literally equivalent to fillRect( x, y, w, h, backgroundColor() ) β same thing, different font. β¨
Examples:
π§½ QPainter::eraseRect ( const QRect & r ) π§½
void QPainter::eraseRect ( const QRect & r )
This is an overloaded member function, provided for convenience β it behaves essentially like the above function.
Erases the area inside the rectangle r. Same energy, just takes a QRect instead of four lil numbers. π«Ά
π¨ QPainter::fillRect ( int x, int y, int w, int h, const QBrush & brush ) π¨
void QPainter::fillRect ( int x, int y, int w, int h, const QBrush & brush )
Fills the rectangle (x, y, w, h) with the brush. Simple as that, no notes.
Fun fact: you can pass a QColor in as the brush, because there's a QBrush constructor that takes a QColor argument and creates a solid pattern brush. So yes, colour directly = valid, go off. π
See also drawRect().
Examples:
π¨ QPainter::fillRect ( const QRect & r, const QBrush & brush ) π¨
void QPainter::fillRect ( const QRect & r, const QBrush & brush )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Fills the rectangle r using brush brush. π
π§ QPainter::flush ( const QRegion & region, CoordinateMode cm = CoordDevice ) π§
void QPainter::flush ( const QRegion & region, CoordinateMode cm = CoordDevice )
Flushes any buffered drawing operations inside the region region, using clipping mode cm. Basically "okay bestie, push it out NOW". π₯
Heads up though: the flush may update the whole device if the platform doesn't support flushing to a specified region. So don't be shocked if she does the most. π
See also CoordinateMode.
π§ QPainter::flush () π§
void QPainter::flush ()
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Flushes any buffered drawing operations. Just all of them. No region specified, we're going wide. β¨
π€ const QFont & QPainter::font () const π€
const QFont & QPainter::font () const
Returns the painter's currently set font. Whatever font she's wearing rn. π
See also setFont() and QFont.
Example: fileiconview/qfileiconview.cpp.
π QFontInfo QPainter::fontInfo () const π
QFontInfo QPainter::fontInfo () const
Returns the font info for the painter β but only if the painter is active. You literally cannot get font information for an inactive painter, so the return value is undefined if the painter isn't active. Not "empty", not "default" β undefined. That's the vibe, don't test her. π
See also fontMetrics() and isActive().
π QFontMetrics QPainter::fontMetrics () const π
QFontMetrics QPainter::fontMetrics () const
Returns the font metrics for the painter β again, only if the painter is active. Metrics for an inactive painter? Not possible. The return value is undefined if the painter is not active. Same rules as fontInfo(), she's consistent. π
See also fontInfo() and isActive().
Examples:
πͺ HDC QPainter::handle () const πͺ
HDC QPainter::handle () const
Returns the platform-dependent handle used for drawing.
Warning bestie: using this function is not portable. It's giving "I know what I'm doing on this specific platform" energy. π«£
βοΈ bool QPainter::hasClipping () const βοΈ
bool QPainter::hasClipping () const
Returns TRUE if clipping has been set; otherwise returns FALSE. A little vibe check for your clip region. β¨
See also setClipping().
Example: themes/wood.cpp.
πͺ bool QPainter::hasViewXForm () const πͺ
bool QPainter::hasViewXForm () const
Returns TRUE if view transformation is enabled; otherwise returns FALSE.
See also setViewXForm() and xForm().
π bool QPainter::hasWorldXForm () const π
bool QPainter::hasWorldXForm () const
Returns TRUE if world transformation is enabled; otherwise returns FALSE.
See also setWorldXForm().
π’ bool QPainter::isActive () const π’
bool QPainter::isActive () const
Returns TRUE if the painter is active painting, i.e. begin() has been called and end() has not yet been called; otherwise returns FALSE.
So basically: is she painting or is she done? That's the whole question. π
See also QPaintDevice::paintingActive().
Examples:
π void QPainter::lineTo ( int x, int y ) π
void QPainter::lineTo ( int x, int y )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Use drawLine() instead, fr fr.
Draws a line from the current pen position to (x, y) and sets (x, y) to be the new current pen position. Two jobs, one call. β¨
See also QPen, moveTo(), drawLine(), and pos().
π void QPainter::lineTo ( const QPoint & p ) π
void QPainter::lineTo ( const QPoint & p )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Draws a line to the point p. π«Ά
ποΈ void QPainter::moveTo ( int x, int y ) ποΈ
void QPainter::moveTo ( int x, int y )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Sets the current pen position to (x, y). That's it, that's the whole job.
See also lineTo() and pos().
ποΈ void QPainter::moveTo ( const QPoint & p ) ποΈ
void QPainter::moveTo ( const QPoint & p )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Moves to the point p. π
ποΈ const QPen & QPainter::pen () const ποΈ
const QPen & QPainter::pen () const
Returns the painter's current pen. The pen she's holding rn, iconic. π
See also setPen().
Examples:
π§ QPoint QPainter::pos () const π§
QPoint QPainter::pos () const
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Returns the current position of the pen. Where's the pen at? There.
See also moveTo().
βοΈ RasterOp QPainter::rasterOp () const βοΈ
RasterOp QPainter::rasterOp () const
Returns the current raster operation. The how-are-the-pixels-combining situation. β¨
See also setRasterOp() and RasterOp.
π void QPainter::redirect ( QPaintDevice * pdev, QPaintDevice * replacement ) π
void QPainter::redirect ( QPaintDevice * pdev, QPaintDevice * replacement )
[static]
Redirects all paint commands for a paint device, pdev, to another paint device, replacement β unless replacement is 0. If replacement is 0, the redirection for pdev is removed. So 0 = cancel the redirect, got it. π
Real talk though: in general, you'll probably find calling QPixmap::grabWidget() or QPixmap::grabWindow() is an easier solution. Just saying. π
π QPainter::resetXForm () π
void QPainter::resetXForm ()
Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldMatrix(), setViewport() and setWindow(). All of them. Back to factory settings bestie. β¨
See also worldMatrix(), viewport(), and window().
β»οΈ QPainter::restore () β»οΈ
void QPainter::restore ()
Restores the current painter state β pops a saved state off the stack. Like hitting undo on the whole state, not just one stroke. π
See also save().
Example: aclock/aclock.cpp.
π« QPainter::restoreWorldMatrix () π«
void QPainter::restoreWorldMatrix ()
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
We recommend using restore() instead. Yeah. That's the note. π
π void QPainter::rotate ( double a ) π
void QPainter::rotate ( double a )
Rotates the coordinate system a degrees counterclockwise. Spinning the whole world, not just one shape. πͺοΈ
See also translate(), scale(), shear(), resetXForm(), setWorldMatrix(), and xForm().
Examples:
πΎ QPainter::save () πΎ
void QPainter::save ()
Saves the current painter state β pushes the state onto a stack. And listen: a save() must be followed by a corresponding restore(). No orphan saves, that's the rule. end() unwinds the stack.
See also restore().
Example: aclock/aclock.cpp.
π« QPainter::saveWorldMatrix () π«
void QPainter::saveWorldMatrix ()
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
We recommend using save() instead. β¨
π void QPainter::scale ( double sx, double sy ) π
void QPainter::scale ( double sx, double sy )
Scales the coordinate system by (sx, sy). Everything gets bigger or smaller, your call. π¦
See also translate(), shear(), rotate(), resetXForm(), setWorldMatrix(), and xForm().
Example: xform/xform.cpp.
π¨ void QPainter::setBackgroundColor ( const QColor & c ) π¨
void QPainter::setBackgroundColor ( const QColor & c )
Sets the background color of the painter to c.
The background color is the color that gets filled in when you draw opaque text, stippled lines and bitmaps. And important: the background color has no effect in transparent background mode β which is, btw, the default. So if you're wondering why nothing's happening, that's why bestie. π
See also backgroundColor(), setBackgroundMode(), and BackgroundMode.
π void QPainter::setBackgroundMode ( BGMode m ) π
void QPainter::setBackgroundMode ( BGMode m )
Sets the background mode of the painter to m, which must be either TransparentMode (the default) or OpaqueMode. Those are the only two options, pick one. β¨
- Transparent mode draws stippled lines and text without setting the background pixels.
- Opaque mode fills that space with the current background color.
Note that in order to draw a bitmap or pixmap transparently, you must use QPixmap::setMask(). Different tool for that job, don't mix them up. π«Ά
See also backgroundMode() and setBackgroundColor().
Example: picture/picture.cpp.
ποΈ void QPainter::setBrush ( BrushStyle style ) ποΈ
void QPainter::setBrush ( BrushStyle style )
Sets the painter's brush to black color and the specified style. Yeah, black. She picked for you. π€
See also brush() and QBrush.
Examples:
ποΈ void QPainter::setBrush ( const QBrush & brush ) ποΈ
void QPainter::setBrush ( const QBrush & brush )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Sets the painter's brush to brush.
The brush defines how shapes are filled. That's the whole point of a brush, no cap. β¨
See also brush().
ποΈ void QPainter::setBrush ( const QColor & color ) ποΈ
void QPainter::setBrush ( const QColor & color )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Sets the painter's brush to have style SolidPattern and the specified color. Solid, one colour, clean. π
See also brush() and QBrush.
π void QPainter::setBrushOrigin ( int x, int y ) π
void QPainter::setBrushOrigin ( int x, int y )
Sets the brush origin to (x, y).
The brush origin specifies the (0, 0) coordinate of the painter's brush. Heads up: this setting only applies to pattern brushes and pixmap brushes. Plain solid brushes don't care, don't @ them. π
See also brushOrigin().
π void QPainter::setBrushOrigin ( const QPoint & p ) π
void QPainter::setBrushOrigin ( const QPoint & p )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Sets the brush origin to point p. π«Ά
βοΈ void QPainter::setClipRect ( int x, int y, int w, int h, CoordinateMode m = CoordDevice ) βοΈ
void QPainter::setClipRect ( int x, int y, int w, int h, CoordinateMode m = CoordDevice )
Sets the clip region to the rectangle x, y, w, h and enables clipping. The clip mode is set to m.
Now the important part:
- If
misCoordDevice(the default), the coordinates given for the clip region are taken to be physical device coordinates and are not subject to any coordinate transformations. - If
misCoordPainter, the coordinates given for the clip region are taken to be model coordinates.
Know which one you're in, bestie. It changes everything. π₯
See also setClipRegion(), clipRegion(), setClipping(), and QPainter::CoordinateMode.
Examples:
βοΈ void QPainter::setClipRect ( const QRect & r, CoordinateMode m = CoordDevice ) βοΈ
void QPainter::setClipRect ( const QRect & r, CoordinateMode m = CoordDevice )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Sets the clip region to the rectangle r and enables clipping. The clip mode is set to m.
See also CoordinateMode.
βοΈ void QPainter::setClipRegion ( const QRegion & rgn, CoordinateMode m = CoordDevice ) βοΈ
void QPainter::setClipRegion ( const QRegion & rgn, CoordinateMode m = CoordDevice )
Sets the clip region to rgn and enables clipping. The clip mode is set to m.
Note that the clip region is given in physical device coordinates and is not subject to any coordinate transformation. So don't expect your transforms to move it, because they won't. π
See also setClipRect(), clipRegion(), setClipping(), and CoordinateMode.
Examples:
π void QPainter::setClipping ( bool enable ) π
void QPainter::setClipping ( bool enable )
Enables clipping if enable is TRUE, or disables clipping if enable is FALSE. On/off, the simplest girlie in the whole file. β¨
See also hasClipping(), setClipRect(), and setClipRegion().
Example: themes/wood.cpp.
π€ void QPainter::setFont ( const QFont & font ) π€
void QPainter::setFont ( const QFont & font )
Sets the painter's font to font.
This font is used by subsequent drawText() functions. And fyi, the text color is the same as the pen color β so if your text is looking weird, check your pen, not your font. π
See also font() and drawText().
Examples:
ποΈ void QPainter::setPen ( const QPen & pen ) ποΈ
void QPainter::setPen ( const QPen & pen )
Sets a new painter pen.
The pen defines how to draw lines and outlines, and it also defines the text color. So she's doing double duty, main character energy fr. π
See also pen().
Examples:
ποΈ void QPainter::setPen ( PenStyle style ) ποΈ
void QPainter::setPen ( PenStyle style )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Sets the painter's pen to have style style, width 0 and black color. That's the preset, take it or use the other overload. π€
See also pen() and QPen.
void QPainter::setPen ( const QColor & color )
okay so this one is an overloaded member function, provided for convenience π it behaves essentially like the above function, no cap.
It sets the painter's pen to have style SolidLine, width 0 and the specified color. that's it, that's the whole vibe β¨
See also pen() and QPen.
void QPainter::setRasterOp ( RasterOp r )
Sets the raster operation to r. The default is CopyROP. π
See also rasterOp() and Qt::RasterOp.
void QPainter::setTabArray ( int * ta )
Sets the tab stop array to ta. This puts tab stops at ta[0], ta[1] and so on. bestie the array is null-terminated π
If both a tab array and a tab top size is set, the tab array wins. periodt.
See also tabArray(), setTabStops(), drawText(), and fontMetrics().
void QPainter::setTabStops ( int ts )
Sets the tab stop width to ts, i.e. locates tab stops at ts, 2*ts, 3*ts and so on. it's giving very orderly β¨
Tab stops are used when drawing formatted text with ExpandTabs set. This fixed tab stop value is used only if no tab array is set (which is the default case, fyi).
A value of 0 (the default) implies a tabstop setting of 8 times the width of the character 'x' in the font currently set on the painter. iconic behavior honestly.
See also tabStops(), setTabArray(), drawText(), and fontMetrics().
void QPainter::setViewXForm ( bool enable )
Enables view transformations if enable is TRUE, or disables view transformations if enable is FALSE. π¦
See also hasViewXForm(), setWindow(), setViewport(), setWorldMatrix(), setWorldXForm(), and xForm().
void QPainter::setViewport ( int x, int y, int w, int h )
Sets the viewport rectangle view transformation for the painter and enables view transformation. slay π
The viewport rectangle is part of the view transformation. The viewport specifies the device coordinate system and is specified by the x, y, w width and h height parameters. Its sister, the window(), specifies the logical coordinate system. sibling energy fr fr.
The default viewport rectangle is the same as the device's rectangle. See the Coordinate System Overview for an overview of coordinate transformation.
See also viewport(), setWindow(), setViewXForm(), setWorldMatrix(), setWorldXForm(), and xForm().
Example: aclock/aclock.cpp.
void QPainter::setViewport ( const QRect & r )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Sets the painter's viewport to rectangle r. easy β¨
void QPainter::setWindow ( int x, int y, int w, int h )
Sets the window rectangle view transformation for the painter and enables view transformation. π
The window rectangle is part of the view transformation. The window specifies the logical coordinate system and is specified by the x, y, w width and h height parameters. Its sister, the viewport(), specifies the device coordinate system. the way these two are literally a duo π
The default window rectangle is the same as the device's rectangle. See the Coordinate System Overview for an overview of coordinate transformation.
See also window(), setViewport(), setViewXForm(), setWorldMatrix(), and setWorldXForm().
Examples:
void QPainter::setWindow ( const QRect & r )
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Sets the painter's window to rectangle r. π
void QPainter::setWorldMatrix ( const QWMatrix & m, bool combine = FALSE )
Sets the world transformation matrix to m and enables world transformation. π
If combine is TRUE, then m is combined with the current transformation matrix, otherwise m replaces the current transformation matrix.
If m is the identity matrix and combine is FALSE, this function calls setWorldXForm(FALSE). (The identity matrix is the matrix where QWMatrix::m11() and QWMatrix::m22() are 1.0 and the rest are 0.0.)
World transformations are applied after the view transformations (i.e. window and viewport).
The following functions can transform the coordinate system without using a QWMatrix:
translate()scale()shear()rotate()
They operate on the painter's worldMatrix() and are implemented like this:
void QPainter::rotate( double a )
{
QWMatrix m;
m.rotate( a );
setWorldMatrix( m, TRUE );
}
Note that you should always use combine when you are drawing into aQPicture. Otherwise it may not be possible to replay the picture with additional transformations. Usingtranslate(),scale(), etc., is safe. π
For a brief overview of coordinate transformation, see the Coordinate System Overview.
See also worldMatrix(), setWorldXForm(), setWindow(), setViewport(), setViewXForm(), xForm(), and QWMatrix.
Examples:
void QPainter::setWorldXForm ( bool enable )
Enables world transformations if enable is TRUE, or disables world transformations if enable is FALSE. The world transformation matrix is not changed, bestie, it stays exactly where it is π
See also setWorldMatrix(), setWindow(), setViewport(), setViewXForm(), and xForm().
void QPainter::shear ( double sh, double sv )
Shears the coordinate system by (sh, sv). the way it just tilts everything πβ¨
See also translate(), scale(), rotate(), resetXForm(), setWorldMatrix(), and xForm().
int * QPainter::tabArray () const
Returns the currently set tab stop array. π
See also setTabArray().
int QPainter::tabStops () const
Returns the tab stop setting.
See also setTabStops().
void QPainter::translate ( double dx, double dy )
Translates the coordinate system by (dx, dy). After this call, (dx, dy) is added to points. lowkey the simplest glow-up ever π
For example, the following code draws the same point twice:
void MyWidget::paintEvent()
{
QPainter paint( this );
paint.drawPoint( 0, 0 );
paint.translate( 100.0, 40.0 );
paint.drawPoint( -100, -40 );
}
See also scale(), shear(), rotate(), resetXForm(), setWorldMatrix(), and xForm().
Examples:
QRect QPainter::viewport () const
Returns the viewport rectangle. π¦
See also setViewport() and setViewXForm().
Example: aclock/aclock.cpp.
QRect QPainter::window () const
Returns the window rectangle.
See also setWindow() and setViewXForm().
const QWMatrix & QPainter::worldMatrix () const
Returns the world transformation matrix. π
See also setWorldMatrix().
QPoint QPainter::xForm ( const QPoint & pv ) const
Returns the point pv transformed from model coordinates to device coordinates. β¨
See also xFormDev() and QWMatrix::map().
QRect QPainter::xForm ( const QRect & rv ) const
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Returns the rectangle rv transformed from model coordinates to device coordinates.
If world transformation is enabled and rotation or shearing has been specified, then the bounding rectangle is returned. okay noted π
See also xFormDev() and QWMatrix::map().
QPointArray QPainter::xForm ( const QPointArray & av ) const
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Returns the point array av transformed from model coordinates to device coordinates.
See also xFormDev() and QWMatrix::map().
QPointArray QPainter::xForm ( const QPointArray & av, int index, int npoints ) const
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Returns the point array av transformed from model coordinates to device coordinates. The index is the first point in the array and npoints denotes the number of points to be transformed. If npoints is negative, all points from av[index] until the last point in the array are transformed. bestie that negative number is doing so much work π
The returned point array consists of the number of points that were transformed.
Example:
QPointArray a(10);
QPointArray b;
b = painter.xForm(a, 2, 4); // b.size() == 4
b = painter.xForm(a, 2, -1); // b.size() == 8
See also xFormDev() and QWMatrix::map().
QRect QPainter::xFormDev ( const QRect & rd ) const
Returns the rectangle rd transformed from device coordinates to model coordinates. π (yes, it's the reverse of xForm(), she's the plot twist)
If world transformation is enabled and rotation or shearing is used, then the bounding rectangle is returned.
See also xForm() and QWMatrix::map().
QPoint QPainter::xFormDev ( const QPoint & pd ) const
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Returns the point pd transformed from device coordinates to model coordinates.
See also xForm() and QWMatrix::map().
QPointArray QPainter::xFormDev ( const QPointArray & ad ) const
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Returns the point array ad transformed from device coordinates to model coordinates.
See also xForm() and QWMatrix::map().
QPointArray QPainter::xFormDev ( const QPointArray & ad, int index, int npoints ) const
This is an overloaded member function, provided for convenience β behaves essentially like the above function.
Returns the point array ad transformed from device coordinates to model coordinates. The index is the first point in the array and npoints denotes the number of points to be transformed. If npoints is negative, all points from ad[index] until the last point in the array are transformed.
The returned point array consists of the number of points that were transformed. β¨
Example:
QPointArray a(10);
QPointArray b;
b = painter.xFormDev(a, 1, 3); // b.size() == 3
b = painter.xFormDev(a, 1, -1); // b.size() == 9
See also xForm() and QWMatrix::map().
πΈ RELATED FUNCTION DOCUMENTATION πΈ
void qDrawPlainRect ( QPainter * p, int x, int y, int w, int h, const QColor & c, int lineWidth, const QBrush * fill )
#include <qdrawutil.h>
Draws the plain rectangle specified by (x, y, w, h) using the painter p. π
The color argument c specifies the line color.
The lineWidth argument specifies the line width.
The rectangle's interior is filled with the fill brush unless fill is 0.
If you want to use a QFrame widget instead, you can make it display a plain rectangle, for example QFrame::setFrameStyle( QFrame::Box | QFrame::Plain ). cute alternative, ngl π
Warning: This function does not look atQWidget::style()orQApplication::style(). Use the drawing functions inQStyleto make widgets that follow the current GUI style. so if ur widget looks cursed in a custom style, this is why bestie π
See also qDrawShadeRect() and QStyle::drawPrimitive().
void qDrawShadeLine ( QPainter * p, int x1, int y1, int x2, int y2, const QColorGroup & g, bool sunken, int lineWidth, int midLineWidth )
#include <qdrawutil.h>
okay bestie, this one draws a horizontal or vertical shaded line using the painter p. horizontal means y1 == y2, vertical means x1 == x2 β that's the whole vibe check right there.
literally nothing gets drawn ify1 != y2andx1 != x2. like, if your line is neither horizontal nor vertical, it's giving nothing, and nothing is what you get π
- the color group argument
gspecifies the shading colors (light, dark and middle colors) β¨ - the line appears sunken if
sunkenisTRUE, or raised ifsunkenisFALSE - the
lineWidthargument specifies the line width for each of the lines. it is not the total line width, bestie, don't get it twisted π - the
midLineWidthargument specifies the width of a middle line drawn in theQColorGroup::mid()color
if you want to use a QFrame widget instead, you can make it display a shaded line, for example:
QFrame::setFrameStyle( QFrame::HLine | QFrame::Sunken )
Warning: this function does not look atQWidget::style()orQApplication::style(). use the drawing functions inQStyleto make widgets that follow the current GUI style. no cap π«Ά
see also qDrawShadeRect(), qDrawShadePanel(), and QStyle::drawPrimitive().
void qDrawShadePanel ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, bool sunken, int lineWidth, const QBrush * fill )
#include <qdrawutil.h>
draws the shaded panel specified by (x, y, w, h) using the painter p. iconic little rectangle with drama around the edges π
- the color group argument
gspecifies the shading colors (light, dark and middle colors) π - the panel appears sunken if
sunkenisTRUE, or raised ifsunkenisFALSE - the
lineWidthargument specifies the line width - the panel's interior is filled with the
fillbrush unlessfillis0β like, zero, nada, nothing, and then it's just vibes and no fill β¨
if you want to use a QFrame widget instead, you can make it display a shaded panel, for example:
QFrame::setFrameStyle( QFrame::Panel | QFrame::Sunken )
Warning: this function does not look atQWidget::style()orQApplication::style(). use the drawing functions inQStyleto make widgets that follow the current GUI style. iykyk π
see also qDrawWinPanel(), qDrawShadeLine(), qDrawShadeRect(), and QStyle::drawPrimitive().
void qDrawShadeRect ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, bool sunken, int lineWidth, int midLineWidth, const QBrush * fill )
#include <qdrawutil.h>
draws the shaded rectangle specified by (x, y, w, h) using the painter p. the rectangle version, main character energy, same iconic shading π
- the color group argument
gspecifies the shading colors (light, dark and middle colors) π - the rectangle appears sunken if
sunkenisTRUE, or raised ifsunkenisFALSE - the
lineWidthargument specifies the line width for each of the lines. it is not the total line width β we been knew π«Ά - the
midLineWidthargument specifies the width of a middle line drawn in theQColorGroup::mid()color - the rectangle's interior is filled with the
fillbrush unlessfillis0πΈ
if you want to use a QFrame widget instead, you can make it display a shaded rectangle, for example:
QFrame::setFrameStyle( QFrame::Box | QFrame::Raised )
Warning: this function does not look atQWidget::style()orQApplication::style(). use the drawing functions inQStyleto make widgets that follow the current GUI style. periodt β¨
see also qDrawShadeLine(), qDrawShadePanel(), qDrawPlainRect(), QStyle::drawItem(), QStyle::drawControl(), and QStyle::drawComplexControl().
void qDrawWinButton ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, bool sunken, const QBrush * fill )
#include <qdrawutil.h>
draws the Windows-style button specified by (x, y, w, h) using the painter p. throwback core π
- the color group argument
gspecifies the shading colors (light, dark and middle colors) π - the button appears sunken if
sunkenisTRUE, or raised ifsunkenisFALSE - the line width is 2 pixels. that's it, that's the number, no arguments π₯
- the button's interior is filled with the
*fillbrush unlessfillis0β¨
Warning: this function does not look atQWidget::style()orQApplication::style(). use the drawing functions inQStyleto make widgets that follow the current GUI style. bestie, i'm serious π«Ά
see also qDrawWinPanel() and QStyle::drawControl().
void qDrawWinPanel ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, bool sunken, const QBrush * fill )
#include <qdrawutil.h>
draws the Windows-style panel specified by (x, y, w, h) using the painter p. yes it's the sibling of the button, they're a matched set π
- the color group argument
gspecifies the shading colors π - the panel appears sunken if
sunkenisTRUE, or raised ifsunkenisFALSE - the line width is 2 pixels β
- the button's interior is filled with the
fillbrush unlessfillis0(yes, the doc really does say "button's" here β not me, not my typo, it's canon π)
if you want to use a QFrame widget instead, you can make it display a shaded panel, for example:
QFrame::setFrameStyle( QFrame::WinPanel | QFrame::Raised )
Warning: this function does not look atQWidget::style()orQApplication::style(). use the drawing functions inQStyleto make widgets that follow the current GUI style. it's giving "do it the right way" π
see also qDrawShadePanel(), qDrawWinButton(), and QStyle::drawPrimitive().
β¨ SEE ALSO β¨
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. slay, legally π«Ά
π¦ AUTHOR π¦
Generated automatically from the source code. no human author, just vibes and a build script β¨
π BUGS π
if you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. good bug reports help us to help you. thank you. (yes bestie, a good bug report is a love language π)
the definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. this man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.
if you find errors in this manual page, please report them to qt-bugs@trolltech.com. please include the name of the manual page (qpainter.3qt) and the Qt version (3.3.8). include both, bestie, they're gonna ask πΈ
and that's a wrap on the whole QPainter(3qt) page!! π this last part dropped from Trolltech AS on 2 February 2007, and yeah the footer says QPainter(3qt) right at the bottom like a little name tag. go forth and paint, you gorgeous genius ππβ¨
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms