![]() ![]() |
The QPainter class paints on paint devices. More...
#include <qpainter.h>
Inherits Qt.
The painter provides efficient graphics rendering on any QPaintDevice object. QPainter 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.
The typical use of a painter is:
Mostly, all this is done inside a paint event. (In fact, 99% of all QPainter use is in a reimplementation of QWidget::paintEvent()). Here's one very simple example:
void SimpleExampleWidget::paintEvent() { QPainter paint( this ); paint.setPen( Qt::blue ); paint.drawText( rect(), AlignCenter, "The Text" ); }
Simple. However, there are many settings you may use:
Opaque
or Transparent,
ie. whether
backgroundColor() is used or not.
Note that 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, changing calling e.g. 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(), and drawQuadBezier().
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() 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.
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 walkthrough of 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 matrix().
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 draws 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 a little speed.
After all the coordinate transformation is done, QPainter can clip the drawing to and 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 too will clip a bit. 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().
Finally, QPainter includes some little-used functions that are very handy the few times you need them.
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. QPainter supports a static function to do this, redirect(). We recommend not using it, but for some hacks it's perfect.
setTabStops() and setTabArray() 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 and Coordinate System Overview
Examples: qtimage/qtimage.cpp grapher/grapher.cpp drawlines/connect.cpp xform/xform.cpp drawdemo/drawdemo.cpp menu/menu.cpp progress/progress.cpp qmag/qmag.cpp splitter/splitter.cpp forever/forever.cpp desktop/desktop.cpp scrollview/scrollview.cpp trivial/trivial.cpp movies/main.cpp picture/picture.cpp
Constructs a painter.
Notice that all painter settings (setPen,setBrush etc.) are reset to default values when begin() is called.
Constructs a painter that begins painting the paint device pd immediately.
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 }
Constructs a painter that begins painting the paint device pd immediately, with the default arguments taken from copyAttributes.
See also: begin().
Destructs the painter.
Returns the current background color.
See also: setBackgroundColor() and QColor.
Returns the current background mode.
See also: setBackgroundMode() and BGMode.
Begins painting the paint device pd and returns TRUE if successful, or FALSE if an error occurs.
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.
Examples: desktop/desktop.cpp picture/picture.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This version opens the painter on a paint device pd and sets the initial pen, background color and font from copyAttributes. This is equivalent with:
QPainter p; p.begin( pd ); p.setPen( copyAttributes->foregroundColor() ); p.setBackgroundColor( copyAttributes->backgroundColor() ); p.setFont( copyAttributes->font() );
This begin function is convenient for double buffering. When you draw in a pixmap instead of directly in a widget (to later bitBlt the pixmap into the widget) you will need to set the widgets's font etc. This function does exactly that.
Example:
void MyWidget::paintEvent( QPaintEvent * ) { QPixmap pm(size()); QPainter p; p.begin(&pm, this); // ... potential flickering paint operation ... p.end(); bitBlt(this, 0, 0, &pm); }
See also: end().
Returns the bounding rectangle of the aligned text that would be printed with the corresponding drawText() function (the first len characters from str). The drawing, and hence the bounding rectangle, is constrained to the rectangle (x,y,w,h).
If len is negative (default value), the whole string is used.
The tf argument is the bitwise OR of the following flags:
AlignLeft
aligns to the left border.
AlignRight
aligns to the right border.
AlignHCenter
aligns horizontally centered.
AlignTop
aligns to the top border.
AlignBottom
aligns to the bottom border.
AlignVCenter
aligns vertically centered
AlignCenter
(= AlignHCenter
| AlignVCenter)
SingleLine
ignores newline characters in the text.
ExpandTabs
expands tabulators.
ShowPrefix
interprets "&x" as "x" underlined.
WordBreak
breaks the text to fit the rectangle.
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.
These flags are defined in qnamespace.h.
See also: drawText(), fontMetrics(), QFontMetrics::boundingRect() and Qt::AlignmentFlags.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the current painter brush.
See also: QPainter::setBrush().
Returns the brush origin currently set.
See also: setBrushOrigin().
[static]
Internal function that cleans up the painter.
Returns the currently set clip region. Note that the clip region is given in physical device coordinates and not subject to any coordinate transformation.
See also: setClipRegion(), setClipRect() and setClipping().
Returns the paint device on which this painter is currently painting, or null if the painter is not active.
See also: QPaintDevice::paintingActive().
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 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().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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 clockwise direction. Zero degrees is at the 3'o clock position.
See also: drawArc() and drawPie().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Draws an ellipse with center at (x+w/2,y+h/2) and size (w,h).
Examples: drawdemo/drawdemo.cpp picture/picture.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Draws at (x, y) the sw by sh area of pixels from (sx, sy) in image, using conversion_flags if the image needs to be converted to a pixmap.
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.
See also: drawPixmap() and QPixmap::convertFromImage().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Draws a line from (x1,y2) to (x2,y2) and sets (x2,y2) to be the new current pen position.
See also: QPen.
Examples: grapher/grapher.cpp drawlines/connect.cpp progress/progress.cpp splitter/splitter.cpp scrollview/scrollview.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Draws nlines separate lines from points defined in a, starting at a[index] (index detaults to 0). If nlines is -1 (the defauls) all points until the end of the array are used (i.e. (a.size()-index)/2 lines are 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.
See also: drawPolyline(), drawPolygon() and QPen.
Replays the picture pic.
This function does exactly the same as QPicture::play().
Examples: picture/picture.cpp
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 clockwise direction. Zero degrees is at the 3'o clock position.
See also: drawArc() and drawChord().
Examples: grapher/grapher.cpp drawdemo/drawdemo.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Draws a pixmap at (x,y) by copying a part of pixmap into the paint device.
(x,y) specify the top-left point in the paint device that is to be drawn onto. (sx,sy) specify the top-left point in pixmap that is to be drawn (the default is (0,0). (sw,sh) specify the size of the pixmap that is to be drawn (the default, (-1,-1), means all the way to the right/bottom of the pixmap).
See also: bitBlt() and QPixmap::setMask().
Examples: qtimage/qtimage.cpp grapher/grapher.cpp qmag/qmag.cpp scrollview/scrollview.cpp movies/main.cpp picture/picture.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This version of the call draws the entire pixmap.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Draws/plots a single point at (x,y) using the current pen.
See also: QPen.
Examples: drawlines/connect.cpp desktop/desktop.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Draws/plots an array of points using the current pen.
If index is non-zero (the default is zero) only points from index are drawn. If npoints is negative (the default) the rest of the points from index are drawn. If is is zero or greater, npoints points are drawn.
Draws the polygon defined by the npoints points in a starting at a[index]. (index defaults to 0.)
If npoints is -1 (the default) all points until the end of the array are used (i.e. a.size()-index line segments define the polygon).
The first point is always connected to the last point.
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, the polygon is filled using the even-odd (alternative) fill algorithm.
See also: drawLineSegments(), drawPolyline() and QPen.
Examples: desktop/desktop.cpp picture/picture.cpp
Draws the polyline defined by the npoints points in a starting at a[index]. (index defaults to 0.)
If npoints is -1 (the default) all points until the end of the array are used (i.e. a.size()-index-1 line segments are drawn).
See also: drawLineSegments(), drawPolygon() and QPen.
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.
Draws a rectangle with upper left corner at (x,y) and with width w and height h.
See also: QPen and drawRoundRect().
Examples: grapher/grapher.cpp drawdemo/drawdemo.cpp forever/forever.cpp trivial/trivial.cpp picture/picture.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Draws a rectangle with round corners at (x,y), with width w and height h.
The xRnd and yRnd arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.
The width and height include all of the drawn lines.
See also: drawRect() and QPen.
Examples: drawdemo/drawdemo.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
As the main version of the function, but with the roundness arguments fixed at 25.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
As the main version of the function, but with the roundness arguments fixed at 25.
Draws at most len characters from str at position (x,y).
(x,y) is the base line position. Note that the meaning of y is not the same for the two drawText() varieties.
Draws at most len characters from str in the rectangle (x,y,w,h).
Note that the meaning of y is not the same for the two drawText() varieties.
This function draws formatted text. The tf text formatting is really of type Qt::AlignmentFlags.
Horizontal alignment defaults to AlignLeft and vertical alignment defaults to AlignTop.
brect (if non-null) is set to the actual bounding rectangle of the output. internal is, yes, internal.
See also: boundingRect().
Examples: grapher/grapher.cpp drawdemo/drawdemo.cpp menu/menu.cpp progress/progress.cpp desktop/desktop.cpp scrollview/scrollview.cpp trivial/trivial.cpp movies/main.cpp picture/picture.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Draws a tiled pixmap in the specified rectangle.
(x,y) specify the top-left point in the paint device that is to be drawn onto. (sx,sy) specify the top-left point in pixmap that is to be drawn (the default is (0,0).
Calling drawTiledPixmap() is similar to calling drawPixmap() several times to fill (tile) an area with a pixmap, but can be much more efficient.
See also: drawPixmap().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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 is used to indicate
keyboard focus (when QApplication::style() is Warning:WindowStyle).
This function draws nothing if the coordinate system has been
rotated or sheared.
See also: drawRect() and QApplication::style().
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 is
used to indicate keyboard focus (when the 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.
See also: drawRect() and QApplication::style().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Ends painting. Any resources used while painting are released.
Note that while you mostly don't need to call end(), the destructor will do it, there is at least one common case, namely double buffering.
QPainter p( myPixmap, this ) // ... p.end(); // stops drawing on myPixmap p.begin( this ); p.drawPixmap( myPixmap );
Since you can't draw a QPixmap while it is being painted, it is necessary to close the active painter.
See also: begin() and isActive().
Examples: desktop/desktop.cpp picture/picture.cpp
Erases the area inside (x,y,w,h).
Equivalent to fillRect( x, y, w, h, backgroundColor() )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Fills the rectangle (x,y,w,h) with the brush.
You can specify a QColor as brush, since there is a QBrush constructor that takes a QColor argument and creates a solid pattern brush.
See also: drawRect().
Examples: progress/progress.cpp scrollview/scrollview.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Flushes any buffered drawing operations.
Returns the currently set painter font.
See also: setFont() and QFont.
Returns the font info for the painter, if the painter is active. It is not possibel to obtain font information for an inactive painter, so the return value is undefined if the painter is not active.
See also: fontMetrics() and isActive().
Returns the font metrics for the painter, if the painter is active. It is not possible to obtain metrics for an inactive painter, so the return value is undefined if the painter is not active.
See also: fontInfo() and isActive().
Examples: drawdemo/drawdemo.cpp desktop/desktop.cpp scrollview/scrollview.cpp movies/main.cpp
Returns TRUE if clipping has been set, otherwise FALSE.
See also: setClipping().
Returns TRUE if view transformation is enabled, otherwise FALSE.
See also: setViewXForm() and xForm().
Returns TRUE if world transformation is enabled, otherwise FALSE.
See also: setWorldXForm().
[static]
Internal function that initializes the painter.
Returns TRUE if the painter is active painting, i.e. begin() has been called and end() has not yet been called.
See also: QPaintDevice::paintingActive().
Examples: desktop/desktop.cpp
Draws a line from the current pen position to (x,y) and sets (x,y) to be the new current pen position.
See also: QPen, moveTo(), drawLine() and pos().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the current pen position to (x,y)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the current pen for the painter.
See also: setPen().
Examples: progress/progress.cpp
Returns the current position of the pen.
See also: moveTo().
Returns the current raster operation.
See also: setRasterOp() and RasterOp.
[static]
Redirects all paint command for a paint device pdev to another paint device replacement, unless replacement is 0. If replacement is 0, the redirection for pdev is removed.
Mostly, you can get better results with less work by calling QPixmap::grabWidget() or QPixmap::grapWindow().
Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldMatrix(), setViewport() and setWindow()
See also: worldMatrix(), viewport() and window().
Restores the current painter state (pops a saved state off the stack).
See also: save().
This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.
We recommend using save() instead.
Rotates the coordinate system a degrees.
See also: translate(), scale(), shear(), resetXForm(), setWorldMatrix() and xForm().
Saves the current painter state (pushes the state onto a stack). A save() must be followed by a corresponding restore(). end() unwinds the stack().
See also: restore().
This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.
We recommend using save() instead.
Scales the coordinate system by (sx,sy).
See also: translate(), shear(), rotate(), resetXForm(), setWorldMatrix() and xForm().
Sets the background color of the painter to c.
The background color is the color that is filled in when drawing opaque text, stippled lines and bitmaps. The background color has no effect in transparent background mode (which is the default).
See also: backgroundColor(), setBackgroundMode() and BackgroundMode.
Sets the background mode of the painter to m, which must be one
of TransparentMode
(the default) and OpaqueMode.
Transparent mode draws stippled lines and text without setting the background pixels. Opaque mode 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() and setBackgroundColor().
Examples: picture/picture.cpp
Sets a new painter brush with black color and the specified style.
Sets a new painter brush.
The brush defines how to fill shapes.
See also: brush().
Examples: grapher/grapher.cpp drawdemo/drawdemo.cpp forever/forever.cpp desktop/desktop.cpp picture/picture.cpp
Sets a new painter brush with the style SolidPattern
and the specified
color.
Sets the brush origin to (x,y).
The brush origin specifies the (0,0) coordinate of the painter's brush. This setting only applies to pattern brushes and pixmap brushes.
See also: brushOrigin().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the clip region to the the rectangle (x,y,w,h) and enables clipping.
Note that the clip region is given in physical device coordinates and not subject to any coordinate transformation.
See also: setClipRegion(), clipRegion() and setClipping().
Examples: qtimage/qtimage.cpp grapher/grapher.cpp progress/progress.cpp splitter/splitter.cpp trivial/trivial.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the clip region to rgn and enables clipping.
Note that the clip region is given in physical device coordinates and not subject to any coordinate transformation.
See also: setClipRect(), clipRegion() and setClipping().
Enables clipping if enable is TRUE, or disables clipping if enable is FALSE.
See also: hasClipping(), setClipRect() and setClipRegion().
Sets a new painter font.
This font is used by subsequent drawText() functions. The text color is the same as the pen color.
See also: font() and drawText().
Examples: grapher/grapher.cpp drawdemo/drawdemo.cpp menu/menu.cpp scrollview/scrollview.cpp movies/main.cpp picture/picture.cpp
Sets a new painter pen with style style,
width 0 and black color.
Examples: grapher/grapher.cpp drawlines/connect.cpp drawdemo/drawdemo.cpp progress/progress.cpp forever/forever.cpp desktop/desktop.cpp scrollview/scrollview.cpp movies/main.cpp
Sets a new painter pen with style SolidLine,
width 0 and the specified
color.
Sets a new painter pen.
The pen defines how to draw lines and outlines, and it also defines the text color.
See also: pen().
Sets the raster operation to r. The default is CopyROP.
See also: rasterOp().
Sets the tab stop array to ta. This puts tab stops at ta[0], ta[1] and so on. The array is null-terminated.
If both a tab array and a tab top size is set, the tab array wins.
See also: tabArray(), setTabStops(), drawText() and fontMetrics().
Set the tab stop width to ts, ie. locates tab stops at ts, 2*ts, 3*ts and so on.
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).
See also: tabStops(), setTabArray(), drawText() and fontMetrics().
Enables view transformations if enable is TRUE, or disables view transformations if enable is FALSE.
See also: hasViewXForm(), setWindow(), setViewport(), setWorldMatrix(), setWorldXForm() and xForm().
Sets the viewport rectangle view transformation for the painter and enables view transformation.
The viewport rectangle is part of the view transformation. The window specifies the device coordinate system. Its sister, the viewport(), specifies the logical coordinate system.
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().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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. Its sister, the viewport(), specifies the device coordinate system.
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: drawdemo/drawdemo.cpp forever/forever.cpp
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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 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:
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 a QPicture. Otherwise it may not be possible to replay the picture with additional transformations. Using translate(), scale(), etc. is safe.
For a brief verview of coordinate transformation, see the Coordinate System Overview.
See also: worldMatrix(), setWorldXForm(), setWindow(), setViewport(), setViewXForm(), xForm() and QWMatrix.
Examples: drawdemo/drawdemo.cpp
Enables world transformations if enable is TRUE, or disables world transformations if enable is FALSE. The world transformation matrix is not changed.
See also: setWorldMatrix(), setWindow(), setViewport(), setViewXForm() and xForm().
Shears the coordinate system (sh,sv).
See also: translate(), scale(), rotate(), resetXForm(), setWorldMatrix() and xForm().
Returns the currently set tab stop array.
See also: setTabArray().
Returns the tab stop setting.
See also: setTabStops().
Translates the coordinate system by (dx,dy).
For example, the following code draws a single vertical line 20 pixels high.
void MyWidget::paintEvent() { QPainter paint( this ); paint.drawLine(10,0,10,20); paint.translate(100.0,100.0); paint.drawLine(-90,-80,-90,-70); }
See also: scale(), shear(), rotate(), resetXForm(), setWorldMatrix() and xForm().
Returns the viewport rectangle.
See also: setViewport() and setViewXForm().
Returns the window rectangle.
See also: setWindow() and setViewXForm().
Returns the world transformation matrix.
See also: setWorldMatrix().
Returns the point pv transformed from model coordinates to device coordinates.
See also: xFormDev() and QWMatrix::map().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the point array av transformed from model coordinates to device coordinates.
See also: xFormDev() and QWMatrix::map().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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.
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().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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.
See also: xFormDev() and QWMatrix::map().
Returns the point pv transformed from device coordinates to model coordinates.
See also: xForm() and QWMatrix::map().
Returns the point array av transformed from device coordinates to model coordinates.
See also: xForm() and QWMatrix::map().
Returns the rectangle rv transformed from device coordinates to model coordinates.
If world transformation is enabled and rotation or shearing is used, then the bounding rectangle is returned.
See also: xForm() and QWMatrix::map().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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 av[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().
#include <qdrawutil.h>
Draws a plain rectangle given 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 interior is filled with the fill brush unless fill is null.
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 )
.
Warning: This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style.
See also: qDrawShadeRect() and QStyle::drawRect().
#include <qdrawutil.h>
Draws a horizontal (y1 == y2) or vertical (x1 == x2) shaded line using the painter p.
Nothing is drawn if y1 != y2 and x1 != x2 (i.e. the line is neither horizontal nor vertical).
The color group argument g specifies the shading colors (light, dark and middle colors).
The line appears sunken if sunken is TRUE, or raised if sunken is FALSE.
The lineWidth argument specifies the line width for each of the lines. It is not the total line width.
The midLineWidth argument specifies the width of a middle line drawn in the QColorGroup::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 at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style.
See also: qDrawShadeRect(), qDrawShadePanel() and QStyle::drawSeparator().
#include <qdrawutil.h>
Draws a Windows-style button given by (x, y, w, h) using the painter p.
The color group argument g specifies the shading colors (light, dark and middle colors).
The button appears sunken if sunken is TRUE, or raised if sunken is FALSE.
The line width is 2 pixels.
The button interior is filled with the *fill brush unless fill is null.
Warning: This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style.
See also: qDrawWinPanel() and QStyle::drawButton().
#include <qdrawutil.h>
Draws a Windows-style panel given by (x, y, w, h) using the painter p.
The color group argument g specifies the shading colors.
The panel appears sunken if sunken is TRUE, or raised if sunken is FALSE.
The line width is 2 pixels.
The button interior is filled with the fill brush unless fill is null.
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 at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style.
See also: qDrawShadePanel(), qDrawWinButton() and QStyle::drawPanel().
#include <qdrawutil.h>
Draws a shaded panel given by (x, y, w, h) using the painter p.
The color group argument g specifies the shading colors (light, dark and middle colors).
The panel appears sunken if sunken is TRUE, or raised if sunken is FALSE.
The lineWidth argument specifies the line width.
The panel interior is filled with the fill brush unless fill is null.
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 at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style.
See also: qDrawWinPanel(), qDrawShadeLine(), qDrawShadeRect() and QStyle::drawPanel().
#include <qdrawutil.h>
Draws a shaded rectangle/box given by (x, y, w, h) using the painter p.
The color group argument g specifies the shading colors (light, dark and middle colors).
The rectangle appears sunken if sunken is TRUE, or raised if sunken is FALSE.
The lineWidth argument specifies the line width for each of the lines. It is not the total line width.
The midLineWidth argument specifies the width of a middle line drawn in the QColorGroup::mid() color.
The rectangle interior is filled with the fill brush unless fill is null.
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 at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style.
See also: qDrawShadeLine(), qDrawShadePanel(), qDrawPlainRect(), QStyle::drawRect() and QStyle::drawRectStrong().
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright İ 2000 Trolltech | Trademarks | Qt version 2.2.0-beta0
|