QPainter Class Reference


The QPainter class paints on paint devices. (details) (complete member list)

#include <qpainter.h>

Public Members

Static Public Members

Private Members


Detailed Description

The QPainter class paints on paint devices.

The painter provides graphics rendering on any QPaintDevice object.

Graphics can be transformed using view transformation, world transformation or a combination of these two. View transformation is a window/viewport transformation with translation and scaling. World transformation is a full 2D transformation including rotation and shearing.

The typical use of a painter is:

  1. Call begin() to begin painting on a device.
  2. Set a pen, a brush etc.
  3. Perform the drawing.
  4. Call end() to finish painting.

Example of use:

  QWidget  widget;
  QPainter paint;
  paint.begin( &widget );
  paint.setPen( blue );
  paint.drawText( 20, 20, 100, 100, AlignCenter, "The Text" );
  paint.end();

Member Function Documentation

QPainter::QPainter ()

Constructs a painter.

QPainter::~QPainter ()

Destroys the painter.

QRect QPainter::boundingRect (int x, int y, int w, int h, int tf, const char *str, int len = -1, char **internal=0)

Returns the bounding rectangle of the aligned text that would be printed with the corresponding drawText() function.

The tf text formatting is the bitwise OR of the following flags:

QRect QPainter::boundingRect (const QRect &r, int tf, const char *str, int len = -1, char **i=0)

Synonymous to boundingRect(x,y,w,h,...).

void QPainter::drawArc (int x, int y, int w, int h, int a1, int a2)

Draws an arc defined by the rectangle (x,y,w,h) and the start angle a1 and the end angle a2.

void QPainter::drawArc (const QRect &r, int a1, int a2)

Synonymous to drawArc(x,y,w,h,a1,a2).

void QPainter::drawBezier (const QPointArray &a, int index=0, int npoints=-1)

Draws a Bezier curve defined by the npoints control points in a, starting at a[index].

void QPainter::drawChord (int x, int y, int w, int h, int a1, int a2)

Draws a chord defined by the rectangle (x,y,w,h) and the start angle a1 and the end angle a2.

void QPainter::drawChord (const QRect &r, int a1, int a2)

Synonymous to drawChord(x,y,w,h,a1,a2).

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

void QPainter::drawEllipse (const QRect &r)

Synonymous to drawEllipse(x,y,w,h).

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

Draws a line from (x1,y2) to (x2,y2).

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

Synonymous to drawLine(x1,y1,x2,y2).

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

Draws the 1st line from a[index] to a[index+1]. Draws the 2nd line from a[index+2] to a[index+3] etc.

void QPainter::drawPicture (const QPicture &pic)

Replays the picture pic.

This function does exactly the same as QPicture::play().

void QPainter::drawPie (int x, int y, int w, int h, int a1, int a2)

Draws a pie defined by the rectangle (x,y,w,h) and the start angle a1 and the end angle a2.

void QPainter::drawPie (const QRect &r, int a1, int a2)

Synonymous to drawPie(x,y,w,h,a1,a2).

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

Draws a pixmap at (x,y).

void QPainter::drawPixmap (const QPoint &p, const QPixmap &pm)

Synonymous to drawPixmap(x,y,pm).

void QPainter::drawPoint (const QPoint &p)

Synonymous to drawPoint(x,y).

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

The first point is connected to the last point.

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

void QPainter::drawRect (int x, int y, int w, int h)

Draws a rectangle with upper left corner at (x,y) and with width w and height h.

The width and height include both lines.

void QPainter::drawRect (const QRect &r)

Synonymous to drawRect(x,y,w,h).

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

Draws a rectangle with round corners at (x,y), with width w and height h.

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

The width and height include both lines.

void QPainter::drawRoundRect (const QRect &r, int xRnd, int yRnd)

Synonymous to drawRoundRect(x,y,w,h,xRnd,yRnd).

void QPainter::drawShadeLine (int x1, int y1, int x2, int y2, const QColor &tColor, const QColor &bColor, int lw=1, const QColor &mColor=black, int mlw=0)

Draw a horizontal (y1 == y2) or vertical (x1 == x2) shaded line.

The tColor argument specifies the top (or left) color and bColor specifies the bottom (or right) color.

The lw argument specifies the line width for each of the lines. It is not the total line width.

The mw argument specifies the width of a middle line drawn in mColor.

If tColor is brighter that bColor, the line appears to be raised from the surface. If tColor is darker that bColor, the line appears to be sunken into the surface.

See also: drawShadeRect() and drawShadePanel().

void QPainter::drawShadeLine (const QPoint &p1, const QPoint &p2, const QColor &tc, const QColor &bc, int lw=1, const QColor &mc=black, int mlw=0)

Synonymous to drawShadeLine(x1,y1,x2,y2,...).

void QPainter::drawShadePanel (int x, int y, int w, int h, const QColor &tColor, const QColor &bColor, int lw=1, const QColor &fColor=black, bool fill=FALSE)

Draw a shaded panel given by (x,y,w,h).

void QPainter::drawShadePanel (const QRect &r, const QColor &tc, const QColor &bc, int lw=1, const QColor &fc=black, bool fill=FALSE)

Synonymous to drawShadePanel(x1,y1,x2,y2,...).

void QPainter::drawShadeRect (int x, int y, int w, int h, const QColor &tColor, const QColor &bColor, int lw=1, const QColor &mColor=black, int mlw=0)

Draw a shaded rectangle given by (x,y,w,h).

The arguments have the same meaning as for drawShadeLine().

See also: drawShadeLine(), drawShadePanel()

void QPainter::drawShadeRect (const QRect &r, const QColor &tc, const QColor &bc, int lw=1, const QColor &mc=black, int mlw=0)

Synonymous to drawShadeRect(x1,y1,x2,y2,...).

void QPainter::drawText (int x, int y, const char *str, int len = -1)

Draws at most len characters from str at position (x,y).

(x,y) is the base line position.

void QPainter::drawText (int x, int y, int w, int h, int tf, const char *str, int len = -1, QRect *brect=0, char **internal=0)

Draws at most len characters from str in the rectangle (x,y,w,h).

This function draws formatted text.

The tf text formatting is the bitwise OR of the following flags:

void QPainter::drawText (const QPoint &p, const char *s, int len = -1)

Synonymous to drawText(x,y,...).

void QPainter::drawText (const QRect &r, int tf, const char *str, int len = -1, QRect *br=0, char **i=0)

Synonymous to drawText(x,y,w,h,...).

void QPainter::eraseRect (int x, int y, int w, int h)

Calls fillRect( x, y, w, h, backgroundColor() ).

void QPainter::eraseRect (const QRect &r)

Synonymous to eraseRect(x,y,w,h).

void QPainter::fillRect (int x, int y, int w, int h, const QColor &color)

Fills the rectangle (x,y,w,h) with a color.

void QPainter::fillRect (const QRect &r, const QColor &c)

Synonymous to fillRect(x,y,w,h,c).

QFont & QPainter::font ()

Returns the current painter font.

void QPainter::lineTo (const QPoint &p)

Synonymous to lineTo(x,y).

void QPainter::moveTo (const QPoint &p)

Synonymous to moveTo(x,y).

bool QPainter::redirect (const QPaintDevice *pd)

Redirects all paint command to a a paint device pd. Careful here!

void QPainter::setBackgroundColor (const QColor &c)

Sets the background color of the painter to c.

See also: backgroundColor().

void QPainter::setBrushOrigin (const QPoint &p)

Synonymous to setBrushOrigin(x,y).

void QPainter::setClipRect (int x, int y, int w, int h)

Synonymous to setViewport(QRect).

void QPainter::setViewport (int x, int y, int w, int h)

Sets the viewport rectangle view transformation for the painter and enables view transformation.

The viewport rectangle is part of the view transformation. View transformations can be combined with world transformations.

See also: viewport(), setViewport() and setWorldMatrix().

void QPainter::setViewport (const QRect &r)

Synonymous to setViewport(x,y,w,h).

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. View transformations can be combined with world transformations.

See also: window(), setViewport() and setWorldMatrix().

void QPainter::setWindow (const QRect &r)

Synonymous to setWindow(x,y,w,h).

void QPainter::setWorldMatrix (const Q2DMatrix &m, bool combine=FALSE)

Sets the world transformation matrix to m.

If combine is TRUE, then m is combined with the current transformation matrix.

See also: worldMatrix(), setWindow() and setViewport().

QPoint QPainter::xForm (const QPoint &pv) const

Returns the point pv transformed from user coordinates to device coordinates.

QRect QPainter::xForm (const QRect &rv) const

Returns the rectangle rv transformed from user coordinates to device coordinates.

If world transformation is enabled and rotation or shearing is used, then the bounding rectangle will be returned.

QPointArray QPainter::xForm (const QPointArray &av) const

Returns the point array av transformed from user coordinates to device coordinates.

QPoint QPainter::xFormDev (const QPoint &pd) const

Returns the point pv transformed from device coordinates to user coordinates.

QRect QPainter::xFormDev (const QRect &rd) const

Returns the rectangle rv transformed from device coordinates to user coordinates.

If world transformation is enabled and rotation or shearing is used, then the bounding rectangle will be returned.

QPointArray QPainter::xFormDev (const QPointArray &ad) const

Returns the point array av transformed from device coordinates to user coordinates.


This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 04:27, 1995/05/20 by the webmaster at Troll Tech