|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QPainter
public class QPainter
The QPainter class performs low-level painting on widgets and other paint devices.
QPainter provides highly optimized functions to do most of the drawing GUI programs require. It can draw everything from simple lines to complex shapes like pies and chords. It can also draw aligned text and pixmaps. Normally, it draws in a "natural" coordinate system, but it can also do view and world transformation. QPainter can operate on any object that inherits the QPaintDevice class.
The common use of QPainter is inside a widget's paint event: Construct and customize (e.g. set the pen or the brush) the painter. Then draw. Remember to destroy the QPainter object after drawing. For example:
void SimpleExampleWidget::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setPen(Qt::blue); painter.setFont(QFont("Arial", 30)); painter.drawText(rect(), Qt::AlignCenter, "Qt"); }
The core functionality of QPainter is drawing, but the class also provide several functions that allows you to customize QPainter's settings and its rendering quality, and others that enable clipping. In addition you can control how different shapes are merged together by specifying the painter's composition mode.
The isActive function indicates whether the painter is active. A painter is activated by the begin function and the constructor that takes a QPaintDevice argument. The end function, and the destructor, deactivates it.
Together with the QPaintDevice and QPaintEngine classes, QPainter form the basis for Qt's paint system. QPainter is the class used to perform drawing operations. QPaintDevice represents a device that can be painted on using a QPainter. QPaintEngine provides the interface that the painter uses to draw onto different types of devices. If the painter is active, device returns the paint device on which the painter paints, and paintEngine returns the paint engine that the painter is currently operating on. For more information, see The Paint System documentation.
Sometimes it is desirable to make someone else paint on an unusual QPaintDevice. QPainter supports a static function to do this, setRedirected.
Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting.
There are several settings that you can customize to make QPainter draw according to your preferences:
Note that some of these settings mirror settings in some paint devices, e.g. QWidget::font(). The QPainter::begin() function (or equivalently the QPainter constructor) copies these attributes from the paint device.
You can at any time save the QPainter's state by calling the save function which saves all the available settings on an internal stack. The restore function pops them back.
QPainter provides functions to draw most primitives: drawPoint, drawPoints, drawLine, drawRect, drawRoundRect, drawEllipse, drawArc, drawPie, drawChord, drawPolyline, drawPolygon, drawConvexPolygon and drawCubicBezier(). The two convenience functions, drawRects and drawLines, draw the given number of rectangles or lines in the given array of QRects or QLines using the current pen and brush.
The QPainter class also provides the fillRect function which fills the given QRect, with the given QBrush, and the eraseRect function that erases the area inside the given rectangle.
All of these functions have both integer and floating point versions.
![]() | Basic Drawing Example The Basic Drawing example shows how to display basic graphics primitives in a variety of styles using the QPainter class. |
If you need to draw a complex shape, especially if you need to do so repeatedly, consider creating a QPainterPath and drawing it using drawPath.
Painter Paths example The QPainterPath class provides a container for painting operations, enabling graphical shapes to be constructed and reused. The Painter Paths example shows how painter paths can be used to build complex shapes for rendering. | ![]() |
QPainter also provides the fillPath function which fills the given QPainterPath with the given QBrush, and the strokePath function that draws the outline of the given path (i.e. strokes the path).
See also the Vector Deformation demo which shows how to use advanced vector techniques to draw text using a QPainterPath, the Gradients demo which shows the different types of gradients that are available in Qt, and the Path Stroking demo which shows Qt's built-in dash patterns and shows how custom patterns can be used to extend the range of available patterns.
![]() | ![]() | ![]() |
Vector Deformation | Gradients | Path Stroking |
---|
There are functions to draw pixmaps/images, namely drawPixmap, drawImage and drawTiledPixmap. Both drawPixmap and drawImage produce the same result, except that drawPixmap is faster on-screen while drawImage may be faster on a QPrinter or other devices.
Text drawing is done using drawText. When you need fine-grained positioning, boundingRect tells you where a given drawText command will draw.
There is a drawPicture function that draws the contents of an entire QPicture. The drawPicture function is the only function that disregards all the painter's settings as QPicture has its own settings.
To get the optimal rendering result using QPainter, you should use the platform independent QImage as paint device; i.e. using QImage will ensure that the result has an identical pixel representation on any platform.
The QPainter class also provides a means of controlling the rendering quality through its RenderHint enum and the support for floating point precision: All the functions for drawing primitives has a floating point version. These are often used in combination with the QPainter::AntiAliasing render hint.
![]() | Concentric Circles Example The Concentric Circles example shows the improved rendering quality that can be obtained using floating point precision and anti-aliasing when drawing custom widgets. The application's main window displays several widgets which are drawn using the various combinations of precision and anti-aliasing. |
The RenderHint enum specifies flags to QPainter that may or may not be respected by any given engine. QPainter::AntiAliasing indicates that the engine should antialias edges of primitives if possible, QPainter::TextAntialiasing indicates that the engine should antialias text if possible, and the QPainter::SmoothPixmapTransform indicates that the engine should use a smooth pixmap transformation algorithm. HighQualityAntialiasing is an OpenGL-specific rendering hint indicating that the engine should use fragment programs and offscreen rendering for antialiasing.
The renderHints function returns a flag that specifies the rendering hints that are set for this painter. Use the setRenderHint function to set or clear the currently set RenderHints.
Normally, the QPainter operates on the device's own coordinate system (usually pixels), but QPainter has good support for coordinate transformations.
![]() | ![]() | ![]() | ![]() |
nop | rotate | scale | translate |
---|
The most commonly used transformations are scaling, rotation, translation and shearing. Use the scale function to scale the coordinate system by a given offset, the rotate function to rotate it clockwise and translate to translate it (i.e. adding a given offset to the points). You can also twist the coordinate system around the origin using the shear function. See the Affine Transformations demo for a visualization of a sheared coordinate system.
See also the Transformations example which shows how transformations influence the way that QPainter renders graphics primitives. In particular it shows how the order of transformations affects the result.
Affine Transformations Demo The Affine Transformations demo show Qt's ability to perform affine transformations on painting operations. The demo also allows the user to experiment with the transformation operations and see the results immediately. | ![]() |
All the tranformation operations operate on the transformation worldMatrix. A matrix transforms a point in the plane to another point. For more information about the transformation matrix, see the The Coordinate System and QMatrix documentation.
The setWorldMatrix function can replace or add to the currently set worldMatrix. The resetMatrix function resets any transformations that were made using translate, scale, shear, rotate, setWorldMatrix, setViewport and setWindow functions. The deviceMatrix returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device. The latter function is only needed when using platform painting commands on the platform dependent handle, and the platform does not do transformations nativly.
When drawing with QPainter, we specify points using logical coordinates which then are converted into the physical coordinates of the paint device. The mapping of the logical coordinates to the physical coordinates are handled by QPainter's combinedMatrix, a combination of viewport and window and worldMatrix. The viewport represents the physical coordinates specifying an arbitrary rectangle, the window describes the same rectangle in logical coordinates, and the worldMatrix is identical with the transformation matrix.
See also The Coordinate System documentation.
QPainter can clip any drawing operation to a rectangle, a region, or a vector path. The current clip is available using the functions clipRegion and clipPath. Whether paths or regions are preferred (faster) depends on the underlying paintEngine. For example, the QImage paint engine prefers paths while the X11 paint engine prefers regions. Setting a clip is done in the painters logical coordinates.
After QPainter's clipping, the paint device may also clip. For example, most widgets clip away the pixels used by child widgets, and most printers clip away an area near the edges of the paper. This additional clipping is not reflected by the return value of clipRegion or hasClipping.
QPainter provides the CompositionMode enum which defines the Porter-Duff rules for digital image compositing; it describes a model for combining the pixels in one image, the source, with the pixels in another image, the destination.
The two most common forms of composition are Source and SourceOver. Source is used to draw opaque objects onto a paint device. In this mode, each pixel in the source replaces the corresponding pixel in the destination. In SourceOver composition mode, the source object is transparent and is drawn on top of the destination.
Note that composition transformation operates pixelwise. For that reason, there is a difference between using the grahic primitive itself and its bounding rectangle: The bounding rect contains pixels with alpha == 0 (i.e the pixels surrounding the primitive). These pixels will overwrite the other image's pixels, affectively clearing those, while the primitive only overwrites its own area.
![]() | Composition Modes Demo The Composition Modes demo, available in Qt's demo directory, allows you to experiment with the various composition modes and see the results immediately. |
Drawing Example
Nested Class Summary | |
---|---|
static class |
QPainter.CompositionMode
Defines the Porter-Duff rules for digital image compositing. |
static class |
QPainter.RenderHint
Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine. |
static class |
QPainter.RenderHints
This QFlag class provides flags for the int enum. |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Constructor Summary | |
---|---|
QPainter()
Constructs a painter. |
|
QPainter(QPaintDeviceInterface arg__1)
Constructs a painter that begins painting the paint arg__1 immediately. |
|
QPainter(QWidget widget)
Creates a QPainter with parent widget. |
Method Summary | |
---|---|
QBrush |
background()
Returns the current background brush. |
Qt.BGMode |
backgroundMode()
Returns the current background mode. |
boolean |
begin(QPaintDeviceInterface arg__1)
Begins painting the paint arg__1 and returns true if successful; otherwise returns false. |
boolean |
begin(QWidget widget)
This method initializes the painter to draw on widget. |
QRect |
boundingRect(int x,
int y,
int w,
int h,
int flags,
java.lang.String text)
Returns the bounding rectangle of the given text as it will appear when drawn inside the rectangle beginning at the point (x, y) with width w and height h. |
QRectF |
boundingRect(QRectF rect,
int flags,
java.lang.String text)
Returns the bounding rectangle of the text as it will appear when drawn inside the given rect with the specified flags using the currently set font; i.e the function tells you where the drawText function will draw when given the same arguments. |
QRectF |
boundingRect(QRectF rect,
java.lang.String text)
Equivalent to boundingRect(rect, text, QTextOption()). |
QRectF |
boundingRect(QRectF rect,
java.lang.String text,
QTextOption o)
Instead of specifying flags as a bitwise OR of the Qt::AlignmentFlag and Qt::TextFlag, this overloaded function takes an o argument. |
QRect |
boundingRect(QRect rect,
int flags,
java.lang.String text)
Returns the bounding rectangle of the text as it will appear when drawn inside the given rect with the specified flags using the currently set font. |
QBrush |
brush()
Returns the painter's current brush. |
QPoint |
brushOrigin()
Returns the currently set brush origin. |
QPainterPath |
clipPath()
Returns the currently clip as a path. |
QRegion |
clipRegion()
Returns the currently set clip region. |
QMatrix |
combinedMatrix()
Returns the transformation matrix combining the current window/viewport and world transformation. |
QTransform |
combinedTransform()
Returns the transformation matrix combining the current window/viewport and world transformation. |
QPainter.CompositionMode |
compositionMode()
Returns the current composition mode. |
QPaintDeviceInterface |
device()
Returns the paint device on which this painter is currently painting, or 0 if the painter is not active. |
QMatrix |
deviceMatrix()
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device. |
QTransform |
deviceTransform()
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device. |
void |
drawArc(int x,
int y,
int w,
int h,
int a,
int alen)
Draws the arc defined by the rectangle beginning at (x, y) with the specified w and h, and the given a and alen. |
void |
drawArc(QRectF rect,
int a,
int alen)
Draws the arc defined by the given rect, a and alen. |
void |
drawArc(QRect arg__1,
int a,
int alen)
Draws the arc defined by the given arg__1, a and alen. |
void |
drawChord(int x,
int y,
int w,
int h,
int a,
int alen)
Draws the chord defined by the rectangle beginning at (x, y) with the specified w and h, and the given a and alen. |
void |
drawChord(QRectF rect,
int a,
int alen)
Draws the chord defined by the given rect, a and alen. |
void |
drawChord(QRect arg__1,
int a,
int alen)
Draws the chord defined by the given arg__1, a and alen. |
void |
drawConvexPolygon(QPolygon polygon)
Draws the convex polygon defined by polygon using the current pen and brush. |
void |
drawConvexPolygon(QPolygonF polygon)
Draws the convex polygon defined by polygon using the current pen and brush. |
void |
drawEllipse(int x,
int y,
int w,
int h)
Draws the ellipse defined by the rectangle beginning at (x, y) with the given w and h. |
void |
drawEllipse(QRect r)
Draws the ellipse defined by the given r. |
void |
drawEllipse(QRectF r)
Draws the ellipse defined by the given r. |
void |
drawImage(int x,
int y,
QImage image)
Equivalent to drawImage(x, y, image, 0, 0, -1, -1, Qt::AutoColor). |
void |
drawImage(int x,
int y,
QImage image,
int sx)
Equivalent to drawImage(x, y, image, sx, 0, -1, -1, Qt::AutoColor). |
void |
drawImage(int x,
int y,
QImage image,
int sx,
int sy)
Equivalent to drawImage(x, y, image, sx, sy, -1, -1, Qt::AutoColor). |
void |
drawImage(int x,
int y,
QImage image,
int sx,
int sy,
int sw)
Equivalent to drawImage(x, y, image, sx, sy, sw, -1, Qt::AutoColor). |
void |
drawImage(int x,
int y,
QImage image,
int sx,
int sy,
int sw,
int sh)
Equivalent to drawImage(x, y, image, sx, sy, sw, sh, Qt::AutoColor). |
void |
drawImage(int x,
int y,
QImage image,
int sx,
int sy,
int sw,
int sh,
Qt.ImageConversionFlag... flags)
Draws an image at (x, y) by copying a part of image into the paint device. |
void |
drawImage(int x,
int y,
QImage image,
int sx,
int sy,
int sw,
int sh,
Qt.ImageConversionFlags flags)
Draws an image at (x, y) by copying a part of image into the paint device. |
void |
drawImage(QPointF p,
QImage image)
Draws the given image at the given p. |
void |
drawImage(QPointF p,
QImage image,
QRectF sr)
Equivalent to drawImage(p, image, sr, Qt::AutoColor). |
void |
drawImage(QPointF p,
QImage image,
QRectF sr,
Qt.ImageConversionFlag... flags)
Draws the rectangular portion sr of the given image with its origin at the given p. |
void |
drawImage(QPointF p,
QImage image,
QRectF sr,
Qt.ImageConversionFlags flags)
Draws the rectangular portion sr of the given image with its origin at the given p. |
void |
drawImage(QPoint p,
QImage image)
Draws the given image at the given p. |
void |
drawImage(QPoint p,
QImage image,
QRect sr)
Equivalent to drawImage(p, image, sr, Qt::AutoColor). |
void |
drawImage(QPoint p,
QImage image,
QRect sr,
Qt.ImageConversionFlag... flags)
Draws the rectangular portion sr of the given image with its origin at the given p. |
void |
drawImage(QPoint p,
QImage image,
QRect sr,
Qt.ImageConversionFlags flags)
Draws the rectangular portion sr of the given image with its origin at the given p. |
void |
drawImage(QRectF r,
QImage image)
Draws the given image into the given r. |
void |
drawImage(QRectF targetRect,
QImage image,
QRectF sourceRect)
Equivalent to drawImage(targetRect, image, sourceRect, Qt::AutoColor). |
void |
drawImage(QRectF targetRect,
QImage image,
QRectF sourceRect,
Qt.ImageConversionFlag... flags)
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device. |
void |
drawImage(QRectF targetRect,
QImage image,
QRectF sourceRect,
Qt.ImageConversionFlags flags)
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device. |
void |
drawImage(QRect r,
QImage image)
Draws the given image into the given r. |
void |
drawImage(QRect targetRect,
QImage image,
QRect sourceRect)
Equivalent to drawImage(targetRect, image, sourceRect, Qt::AutoColor). |
void |
drawImage(QRect targetRect,
QImage image,
QRect sourceRect,
Qt.ImageConversionFlag... flags)
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device. |
void |
drawImage(QRect targetRect,
QImage image,
QRect sourceRect,
Qt.ImageConversionFlags flags)
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device. |
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2). |
void |
drawLine(QLine line)
Draws a line defined by line. |
void |
drawLine(QLineF line)
Draws a line defined by line. |
void |
drawLine(QPointF p1,
QPointF p2)
Draws a line from p1 to p2. |
void |
drawLine(QPoint p1,
QPoint p2)
Draws a line from p1 to p2. |
void |
drawLines(java.util.List<QLine> lines)
Draws the set of lines defined by the list lines using the current pen and brush. |
void |
drawLinesF(java.util.List<QLineF> lines)
Draws the set of lines defined by the list lines using the current pen and brush. |
void |
drawLinesFromPoints(java.util.List<QPoint> pointPairs)
Draws a line for each pair of points in the vector pointPairs using the current pen. |
void |
drawLinesFromPointsF(java.util.List<QPointF> pointPairs)
Draws a line for each pair of points in the vector pointPairs using the current pen. |
void |
drawPath(QPainterPath path)
Draws the given painter path using the current pen for outline and the current brush for filling. |
void |
drawPicture(int x,
int y,
QPicture picture)
Draws the given picture at point (x, y). |
void |
drawPicture(QPointF p,
QPicture picture)
Replays the given picture at the given p. |
void |
drawPicture(QPoint p,
QPicture picture)
Replays the given picture at the given p. |
void |
drawPie(int x,
int y,
int w,
int h,
int a,
int alen)
Draws the pie defined by the rectangle beginning at (x, y) with the specified w and h, and the given a and alen. |
void |
drawPie(QRectF rect,
int a,
int alen)
Draws a pie defined by the given rect, a and and alen. |
void |
drawPie(QRect arg__1,
int a,
int alen)
Draws a pie defined by the given arg__1, a and and alen. |
void |
drawPixmap(int x,
int y,
int w,
int h,
QPixmap pm)
Draws the pm into the rectangle at position (x, y) with the given w and h. |
void |
drawPixmap(int x,
int y,
int w,
int h,
QPixmap pm,
int sx,
int sy,
int sw,
int sh)
Draws the rectangular portion with the origin (sx, sy), width sw and height sh, of the given pm , at the point (x, y), with a width of w and a height of h. |
void |
drawPixmap(int x,
int y,
QPixmap pm)
Draws the given pm at position (x, y). |
void |
drawPixmap(int x,
int y,
QPixmap pm,
int sx,
int sy,
int sw,
int sh)
Draws a pixmap at (x, y) by copying a part of the given pm into the paint device. |
void |
drawPixmap(QPointF p,
QPixmap pm)
Draws the given pm with its origin at the given p. |
void |
drawPixmap(QPointF p,
QPixmap pm,
QRectF sr)
Draws the rectangular portion sr of the given pm with its origin at the given p. |
void |
drawPixmap(QPoint p,
QPixmap pm)
Draws the given pm with its origin at the given p. |
void |
drawPixmap(QPoint p,
QPixmap pm,
QRect sr)
Draws the rectangular portion sr of the given pm with its origin at the given p. |
void |
drawPixmap(QRectF targetRect,
QPixmap pixmap,
QRectF sourceRect)
Draws the rectangular portion sourceRect of the given pixmap into the given targetRect in the paint device. |
void |
drawPixmap(QRect r,
QPixmap pm)
Draws the given pm into the given r. |
void |
drawPixmap(QRect targetRect,
QPixmap pixmap,
QRect sourceRect)
Draws the rectangular portion sourceRect of the given pixmap into the given targetRect in the paint device. |
void |
drawPoint(int x,
int y)
Draws a single point at position (x, y). |
void |
drawPoint(QPoint p)
Draws a single point at the given p using the current pen's color. |
void |
drawPoint(QPointF pt)
Draws a single point at the given pt using the current pen's color. |
void |
drawPoints(QPolygon points)
Draws the points in the vector points. |
void |
drawPoints(QPolygonF points)
Draws the points in the vector points. |
void |
drawPolygon(QPolygon polygon)
Equivalent to drawPolygon(polygon, Qt::OddEvenFill). |
void |
drawPolygon(QPolygonF polygon)
Equivalent to drawPolygon(polygon, Qt::OddEvenFill). |
void |
drawPolygon(QPolygonF polygon,
Qt.FillRule fillRule)
Draws the polygon defined by the given polygon using the fill rule fillRule. |
void |
drawPolygon(QPolygon polygon,
Qt.FillRule fillRule)
Draws the polygon defined by the given polygon using the fill rule fillRule. |
void |
drawPolyline(QPolygon polygon)
Draws the polyline defined by the given polygon using the current pen. |
void |
drawPolyline(QPolygonF polyline)
Draws the polyline defined by the given polyline using the current pen. |
void |
drawRect(int x1,
int y1,
int w,
int h)
Draws a rectangle with upper left corner at (x1, y1) and with the given w and h. |
void |
drawRect(QRect rect)
Draws the current rect with the current pen and brush. |
void |
drawRect(QRectF rect)
Draws the current rect with the current pen and brush. |
void |
drawRects(java.util.List<QRect> rectangles)
Draws the given rectangles using the current pen and brush. |
void |
drawRectsF(java.util.List<QRectF> rectangles)
Draws the given rectangles using the current pen and brush. |
void |
drawRoundRect(int x,
int y,
int w,
int h)
Equivalent to drawRoundRect(x, y, w, h, 25, 25). |
void |
drawRoundRect(int x,
int y,
int w,
int h,
int arg__5)
Equivalent to drawRoundRect(x, y, w, h, arg__5, 25). |
void |
drawRoundRect(int x,
int y,
int w,
int h,
int arg__5,
int arg__6)
Draws the rectangle x, y, w, h with rounded corners. |
void |
drawRoundRect(QRect r)
Equivalent to drawRoundRect(r, 25, 25). |
void |
drawRoundRect(QRectF r)
Equivalent to drawRoundRect(r, 25, 25). |
void |
drawRoundRect(QRectF r,
int xround)
Equivalent to drawRoundRect(r, xround, 25). |
void |
drawRoundRect(QRectF r,
int xround,
int yround)
Draws a rectangle r with rounded corners. |
void |
drawRoundRect(QRect r,
int xround)
Equivalent to drawRoundRect(r, xround, 25). |
void |
drawRoundRect(QRect r,
int xround,
int yround)
Draws the rectangle r with rounded corners. |
void |
drawText(int x,
int y,
int width,
int height,
int flags,
java.lang.String text)
This is an overloaded method provided for convenience. |
void |
drawText(int x,
int y,
int width,
int height,
int flags,
java.lang.String text,
QRect boundingRect)
Draws the given text within the rectangle with origin (x, y), width and height. |
void |
drawText(int x,
int y,
java.lang.String s)
Draws the given s at position (x, y), using the painter's currently defined text direction. |
void |
drawText(QPointF p,
java.lang.String s)
Draws the given s with the currently defined text direction, beginning at the given p. |
void |
drawText(QPoint p,
java.lang.String s)
Draws the given s with the currently defined text direction, beginning at the given p. |
void |
drawText(QRectF rectangle,
int flags,
java.lang.String text)
This is an overloaded method provided for convenience. |
void |
drawText(QRectF rectangle,
int flags,
java.lang.String text,
QRectF boundingRect)
Draws the given text within the provided rectangle. |
void |
drawText(QRectF r,
java.lang.String text)
Equivalent to drawText(r, text, QTextOption()). |
void |
drawText(QRectF r,
java.lang.String text,
QTextOption o)
Draws the given text in the r specified using the o to control its positioning and orientation. |
void |
drawText(QRect rectangle,
int flags,
java.lang.String text)
This is an overloaded function provided for convenience. |
void |
drawText(QRect rectangle,
int flags,
java.lang.String text,
QRect boundingRect)
Draws the given text within the provided rectangle. |
void |
drawTextItem(int x,
int y,
QTextItem ti)
|
void |
drawTextItem(QPointF p,
QTextItem ti)
|
void |
drawTextItem(QPoint p,
QTextItem ti)
|
void |
drawTiledPixmap(int x,
int y,
int w,
int h,
QPixmap arg__5)
Equivalent to drawTiledPixmap(x, y, w, h, arg__5, 0, 0). |
void |
drawTiledPixmap(int x,
int y,
int w,
int h,
QPixmap arg__5,
int sx)
Equivalent to drawTiledPixmap(x, y, w, h, arg__5, sx, 0). |
void |
drawTiledPixmap(int x,
int y,
int w,
int h,
QPixmap arg__5,
int sx,
int sy)
Draws a tiled arg__5 in the specified rectangle. |
void |
drawTiledPixmap(QRectF rect,
QPixmap pm)
Equivalent to drawTiledPixmap(rect, pm, QPointF()). |
void |
drawTiledPixmap(QRectF rect,
QPixmap pm,
QPointF offset)
Draws a tiled pm, inside the given rect with its origin at the given offset. |
void |
drawTiledPixmap(QRect arg__1,
QPixmap arg__2)
Equivalent to drawTiledPixmap(arg__1, arg__2, QPoint()). |
void |
drawTiledPixmap(QRect arg__1,
QPixmap arg__2,
QPoint arg__3)
Draws a tiled arg__2, inside the given arg__1 with its origin at the given arg__3. |
boolean |
end()
Ends painting. |
void |
eraseRect(int x,
int y,
int w,
int h)
Erases the area inside the rectangle beginning at (x, y) with the given w and h. |
void |
eraseRect(QRect arg__1)
Erases the area inside the given arg__1. |
void |
eraseRect(QRectF arg__1)
Erases the area inside the given arg__1. |
void |
fillPath(QPainterPath path,
QBrush brush)
Fills the given path using the given brush. |
void |
fillRect(int x,
int y,
int w,
int h,
QBrush arg__5)
Fills the rectangle beginning at (x, y) with the given w and h, using the given arg__5. |
void |
fillRect(QRectF arg__1,
QBrush arg__2)
Fills the given arg__1 with the given arg__2. |
void |
fillRect(QRect arg__1,
QBrush arg__2)
Fills the given arg__1 with the given arg__2. |
QFont |
font()
Returns the currently set font used for drawing text. |
QFontInfo |
fontInfo()
Returns the font info for the painter if the painter is active. |
QFontMetrics |
fontMetrics()
Returns the font metrics for the painter if the painter is active. |
static QPainter |
fromNativePointer(QNativePointer nativePointer)
This function returns the QPainter instance pointed to by nativePointer |
boolean |
hasClipping()
Returns true if clipping has been set; otherwise returns false. |
void |
initFrom(QWidget widget)
Initializes the painters pen, background and font to the same as the given widget. |
boolean |
isActive()
Returns true if begin has been called and end has not yet been called; otherwise returns false. |
Qt.LayoutDirection |
layoutDirection()
Returns the layout direction used by the painter when drawing text. |
double |
opacity()
Returns the opacity of the painter. |
QPaintEngine |
paintEngine()
Returns the paint engine that the painter is currently operating on if the painter is active; otherwise 0. |
QPen |
pen()
Returns the painter's current pen. |
static QPaintDeviceInterface |
redirected(QPaintDeviceInterface device,
QPoint offset)
Returns the replacement for given device. |
QPainter.RenderHints |
renderHints()
Returns a flag that specifies the rendering hints that are set for this painter. |
void |
resetMatrix()
Resets any transformations that were made using translate, scale, shear, rotate, setWorldMatrix, setViewport and setWindow. |
void |
resetTransform()
Resets any transformations that were made using translate, scale, shear, rotate, setWorldTransform, setViewport and setWindow. |
void |
restore()
Restores the current painter state (pops a saved state off the stack). |
static void |
restoreRedirected(QPaintDeviceInterface device)
Restores the previous redirection for the given device after a call to setRedirected. |
void |
rotate(double a)
Rotates the coordinate system the given a clockwise. |
void |
save()
Saves the current painter state (pushes the state onto a stack). |
void |
scale(double sx,
double sy)
Scales the coordinate system by (sx, sy). |
void |
setBackground(QBrush bg)
Sets the background brush of the painter to the given bg. |
void |
setBackgroundMode(Qt.BGMode mode)
Sets the background mode of the painter to the given mode |
void |
setBrush(QBrush brush)
Sets the painter's brush to the given brush. |
void |
setBrush(QColor color)
Sets the brush of this QPainter to a solid color brush. |
void |
setBrush(QGradient gradient)
Sets this QPainter's brush to use gradient. |
void |
setBrush(QPixmap pm)
Sets this QPainter's brush to use pm. |
void |
setBrush(Qt.BrushStyle style)
Sets the painter's brush to black color and the specified style. |
void |
setBrushOrigin(int x,
int y)
Sets the brush's origin to point (x, y). |
void |
setBrushOrigin(QPoint arg__1)
Sets the brush's origin to the given arg__1. |
void |
setBrushOrigin(QPointF arg__1)
Sets the brush origin to arg__1. |
void |
setClipPath(QPainterPath path)
Equivalent to setClipPath(path, Qt::ReplaceClip). |
void |
setClipPath(QPainterPath path,
Qt.ClipOperation op)
Enables clipping, and sets the clip path for the painter to the given path, with the clip op. |
void |
setClipping(boolean enable)
Enables clipping if enable is true, or disables clipping if enable is false. |
void |
setClipRect(int x,
int y,
int w,
int h)
Equivalent to setClipRect(x, y, w, h, Qt::ReplaceClip). |
void |
setClipRect(int x,
int y,
int w,
int h,
Qt.ClipOperation op)
Enables clipping, and sets the clip region to the rectangle beginning at (x, y) with the given w and h. |
void |
setClipRect(QRect arg__1)
Equivalent to setClipRect(arg__1, Qt::ReplaceClip). |
void |
setClipRect(QRectF arg__1)
Equivalent to setClipRect(arg__1, Qt::ReplaceClip). |
void |
setClipRect(QRectF arg__1,
Qt.ClipOperation op)
Enables clipping, and sets the clip region to the given arg__1 using the given clip op. |
void |
setClipRect(QRect arg__1,
Qt.ClipOperation op)
Enables clipping, and sets the clip region to the given arg__1 using the given clip op. |
void |
setClipRegion(QRegion arg__1)
Equivalent to setClipRegion(arg__1, Qt::ReplaceClip). |
void |
setClipRegion(QRegion arg__1,
Qt.ClipOperation op)
Sets the clip region to the given arg__1 using the specified clip op. |
void |
setCompositionMode(QPainter.CompositionMode mode)
Sets the composition mode to the given mode. |
void |
setFont(QFont f)
Sets the painter's font to the given f. |
void |
setLayoutDirection(Qt.LayoutDirection direction)
Sets the layout direction used by the painter when drawing text, to the specified direction. |
void |
setOpacity(double opacity)
Sets the opacity of the painter to opacity. |
void |
setPen(QColor color)
Sets the painter's pen to have style Qt::SolidLine, width 0 and the specified color. |
void |
setPen(QPen pen)
Sets the painter's pen to be the given pen. |
void |
setPen(Qt.PenStyle style)
Sets the painter's pen to have the given style, width 0 and black color. |
static void |
setRedirected(QPaintDeviceInterface device,
QPaintDeviceInterface replacement)
Equivalent to setRedirected(device, replacement, QPoint()). |
static void |
setRedirected(QPaintDeviceInterface device,
QPaintDeviceInterface replacement,
QPoint offset)
Redirects all paint commands for the given paint device, to the replacement device. |
void |
setRenderHint(QPainter.RenderHint hint)
Equivalent to setRenderHint(hint, true). |
void |
setRenderHint(QPainter.RenderHint hint,
boolean on)
Sets the given render hint on the painter if on is true; otherwise clears the render hint. |
void |
setRenderHints(QPainter.RenderHints hints)
Equivalent to setRenderHints(hints, true). |
void |
setRenderHints(QPainter.RenderHints hints,
boolean on)
Sets the given render hints on the painter if on is true; otherwise clears the render hints. |
void |
setTransform(QTransform transform)
Equivalent to setTransform(transform, false). |
void |
setTransform(QTransform transform,
boolean combine)
Sets the world transformation matrix. |
void |
setViewport(int x,
int y,
int w,
int h)
Sets the painter's viewport rectangle to be the rectangle beginning at (x, y) with the given w and h. |
void |
setViewport(QRect viewport)
Sets the painter's viewport rectangle to the given viewport, and enables view transformations. |
void |
setViewTransformEnabled(boolean enable)
Enables view transformations if enable is true, or disables view transformations if enable is false. |
void |
setWindow(int x,
int y,
int w,
int h)
Sets the painter's window to the rectangle beginning at (x, y) and the given w and h. |
void |
setWindow(QRect window)
Sets the painter's window to the given window, and enables view transformations. |
void |
setWorldMatrix(QMatrix matrix)
Equivalent to setWorldMatrix(matrix, false). |
void |
setWorldMatrix(QMatrix matrix,
boolean combine)
Sets the transformation matrix to matrix and enables transformations. |
void |
setWorldMatrixEnabled(boolean enabled)
Enables transformations if enabled is true, or disables transformations if enabled is false. |
void |
setWorldTransform(QTransform matrix)
Equivalent to setWorldTransform(matrix, false). |
void |
setWorldTransform(QTransform matrix,
boolean combine)
Sets the world transformation matrix. |
void |
shear(double sh,
double sv)
Shears the coordinate system by (sh, sv). |
void |
strokePath(QPainterPath path,
QPen pen)
Draws the outline (strokes) the path path with the pen specified by pen |
boolean |
testRenderHint(QPainter.RenderHint hint)
Returns true if hint is set; otherwise returns false. |
QTransform |
transform()
Returns the world transformation matrix. |
void |
translate(double dx,
double dy)
Translates the coordinate system by the vector (dx, dy). |
void |
translate(QPoint offset)
Translates the coordinate system by the given offset. |
void |
translate(QPointF offset)
Translates the coordinate system by the given offset; i.e. the given offset is added to points. |
QRect |
viewport()
Returns the viewport rectangle. |
boolean |
viewTransformEnabled()
Returns true if view transformation is enabled; otherwise returns false. |
QRect |
window()
Returns the window rectangle. |
QMatrix |
worldMatrix()
Returns the world transformation matrix. |
boolean |
worldMatrixEnabled()
Returns true if world transformation is enabled; otherwise returns false. |
QTransform |
worldTransform()
Returns the world transformation matrix. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QPainter()
Constructs a painter.
public QPainter(QPaintDeviceInterface arg__1)
Constructs a painter that begins painting the paint arg__1 immediately.
This constructor is convenient for short-lived painters, e.g. in a QWidget::paintEvent() and should be used only once. The constructor calls begin for you and the QPainter destructor automatically calls end.
Here's an example using begin and end:
void MyWidget::paintEvent(QPaintEvent *)
{
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.
public QPainter(QWidget widget)
Method Detail |
---|
public final QBrush background()
Returns the current background brush.
Settings
public final Qt.BGMode backgroundMode()
Returns the current background mode.
Settings
public final boolean begin(QPaintDeviceInterface arg__1)
Begins painting the paint arg__1 and returns true if successful; otherwise returns false.
Notice that all painter settings (setPen, setBrush etc.) are reset to default values when begin is called.
The errors that can occur are serious problems, such as these:
painter->begin(0); // impossible - paint device cannot be 0 QPixmap image(0, 0); painter->begin(&image); // impossible - image.isNull() == true; painter->begin(myWidget); painter2->begin(myWidget); // impossible - only one painter at a time
Note that most of the time, you can use one of the constructors instead of begin, and that end is automatically done at destruction.
Warning: A paint device can only be painted by one painter at a time.
public final QRectF boundingRect(QRectF rect, java.lang.String text)
Equivalent to boundingRect(rect, text, QTextOption()).
public final QRectF boundingRect(QRectF rect, java.lang.String text, QTextOption o)
Instead of specifying flags as a bitwise OR of the Qt::AlignmentFlag and Qt::TextFlag, this overloaded function takes an o argument. The QTextOption class provides a description of general rich text properties.
public final QRect boundingRect(QRect rect, int flags, java.lang.String text)
Returns the bounding rectangle of the text as it will appear when drawn inside the given rect with the specified flags using the currently set font.
public final QRectF boundingRect(QRectF rect, int flags, java.lang.String text)
Returns the bounding rectangle of the text as it will appear when drawn inside the given rect with the specified flags using the currently set font; i.e the function tells you where the drawText function will draw when given the same arguments.
If the text does not fit within the given rect using the specified flags, the function returns the required rectangle.
The flags argument is a bitwise OR of the following flags:
If several of the horizontal or several of the vertical alignment flags are set, the resulting alignment is undefined.
Qt::Alignment
,
Qt::TextFlagpublic final QRect boundingRect(int x, int y, int w, int h, int flags, java.lang.String text)
Returns the bounding rectangle of the given text as it will appear when drawn inside the rectangle beginning at the point (x, y) with width w and height h.
public final QBrush brush()
Returns the painter's current brush.
Settings
public final QPoint brushOrigin()
Returns the currently set brush origin.
Settings
public final QPainterPath clipPath()
Returns the currently clip as a path. Note that the clip path is given in logical coordinates.
public final QRegion clipRegion()
Returns the currently set clip region. Note that the clip region is given in logical coordinates.
public final QMatrix combinedMatrix()
Returns the transformation matrix combining the current window/viewport and world transformation.
It is advisable to use combinedTransform instead of this function to preserve the properties of perspective transformations.
public final QTransform combinedTransform()
Returns the transformation matrix combining the current window/viewport and world transformation.
public final QPainter.CompositionMode compositionMode()
Returns the current composition mode.
public final QPaintDeviceInterface device()
Returns the paint device on which this painter is currently painting, or 0 if the painter is not active.
public final QMatrix deviceMatrix()
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.
Note: It is advisable to use deviceTransform instead of this function to preserve the properties of perspective transformations.
This function is only needed when using platform painting commands on the platform dependent handle (Qt::HANDLE), and the platform does not do transformations nativly.
The QPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.
public final QTransform deviceTransform()
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.
This function is only needed when using platform painting commands on the platform dependent handle (Qt::HANDLE), and the platform does not do transformations nativly.
The QPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.
public final void drawArc(QRectF rect, int a, int alen)
Draws the arc defined by the given rect, a and alen.
The a and alen must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.
![]() | QRectF rectangle(10.0, 20.0, 80.0, 60.0); int startAngle = 30 * 16; int spanAngle = 120 * 16; QPainter painter(this); painter.drawArc(rectangle, startAngle, spanAngle); |
public final void drawArc(int x, int y, int w, int h, int a, int alen)
Draws the arc defined by the rectangle beginning at (x, y) with the specified w and h, and the given a and alen.
public final void drawArc(QRect arg__1, int a, int alen)
Draws the arc defined by the given arg__1, a and alen.
public final void drawChord(int x, int y, int w, int h, int a, int alen)
Draws the chord defined by the rectangle beginning at (x, y) with the specified w and h, and the given a and alen.
public final void drawChord(QRect arg__1, int a, int alen)
Draws the chord defined by the given arg__1, a and alen.
public final void drawChord(QRectF rect, int a, int alen)
Draws the chord defined by the given rect, a and alen. The chord is filled with the current brush.
The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.
![]() | QRectF rectangle(10.0, 20.0, 80.0, 60.0); int startAngle = 30 * 16; int spanAngle = 120 * 16; QPainter painter(this); painter.drawChord(rect, startAngle, spanAngle); |
public final void drawConvexPolygon(QPolygonF polygon)
Draws the convex polygon defined by polygon using the current pen and brush.
public final void drawConvexPolygon(QPolygon polygon)
Draws the convex polygon defined by polygon using the current pen and brush.
public final void drawEllipse(QRectF r)
Draws the ellipse defined by the given r.
A filled ellipse has a size of r.size(). A stroked ellipse has a size of r.size() plus the pen width.
![]() | QRectF rectangle(10.0, 20.0, 80.0, 60.0); QPainter painter(this); painter.drawEllipse(rectangle); |
public final void drawEllipse(QRect r)
Draws the ellipse defined by the given r.
public final void drawEllipse(int x, int y, int w, int h)
Draws the ellipse defined by the rectangle beginning at (x, y) with the given w and h.
public final void drawImage(QPoint p, QImage image, QRect sr, Qt.ImageConversionFlag... flags)
Draws the rectangular portion sr of the given image with its origin at the given p.
public final void drawImage(QPoint p, QImage image, QRect sr)
Equivalent to drawImage(p, image, sr, Qt::AutoColor).
public final void drawImage(QPoint p, QImage image, QRect sr, Qt.ImageConversionFlags flags)
Draws the rectangular portion sr of the given image with its origin at the given p.
public final void drawImage(QPointF p, QImage image, QRectF sr, Qt.ImageConversionFlag... flags)
Draws the rectangular portion sr of the given image with its origin at the given p.
public final void drawImage(QPointF p, QImage image, QRectF sr)
Equivalent to drawImage(p, image, sr, Qt::AutoColor).
public final void drawImage(QPointF p, QImage image, QRectF sr, Qt.ImageConversionFlags flags)
Draws the rectangular portion sr of the given image with its origin at the given p.
public final void drawImage(QRect r, QImage image)
Draws the given image into the given r.
public final void drawImage(QRectF targetRect, QImage image, QRectF sourceRect, Qt.ImageConversionFlag... flags)
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device.
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to specify how you would prefer this to happen.
QRectF target(10.0, 20.0, 80.0, 60.0); QRectF source(0.0, 0.0, 70.0, 40.0); QImage image(":/images/myImage.png"); QPainter(this); painter.drawImage(target, image, source); |
public final void drawImage(QRectF targetRect, QImage image, QRectF sourceRect)
Equivalent to drawImage(targetRect, image, sourceRect, Qt::AutoColor).
public final void drawImage(QRectF targetRect, QImage image, QRectF sourceRect, Qt.ImageConversionFlags flags)
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device.
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to specify how you would prefer this to happen.
QRectF target(10.0, 20.0, 80.0, 60.0); QRectF source(0.0, 0.0, 70.0, 40.0); QImage image(":/images/myImage.png"); QPainter(this); painter.drawImage(target, image, source); |
public final void drawImage(int x, int y, QImage image, int sx, int sy, int sw, int sh, Qt.ImageConversionFlag... flags)
Draws an image at (x, y) by copying a part of image into the paint device.
(x, y) specifies the top-left point in the paint device that is to be drawn onto. (sx, sy) specifies the top-left point in image that is to be drawn. The default is (0, 0).
(sw, sh) specifies the size of the image that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the image.
public final void drawImage(int x, int y, QImage image, int sx, int sy, int sw, int sh)
Equivalent to drawImage(x, y, image, sx, sy, sw, sh, Qt::AutoColor).
public final void drawImage(int x, int y, QImage image, int sx, int sy, int sw)
Equivalent to drawImage(x, y, image, sx, sy, sw, -1, Qt::AutoColor).
public final void drawImage(int x, int y, QImage image, int sx, int sy)
Equivalent to drawImage(x, y, image, sx, sy, -1, -1, Qt::AutoColor).
public final void drawImage(int x, int y, QImage image, int sx)
Equivalent to drawImage(x, y, image, sx, 0, -1, -1, Qt::AutoColor).
public final void drawImage(int x, int y, QImage image)
Equivalent to drawImage(x, y, image, 0, 0, -1, -1, Qt::AutoColor).
public final void drawImage(int x, int y, QImage image, int sx, int sy, int sw, int sh, Qt.ImageConversionFlags flags)
Draws an image at (x, y) by copying a part of image into the paint device.
(x, y) specifies the top-left point in the paint device that is to be drawn onto. (sx, sy) specifies the top-left point in image that is to be drawn. The default is (0, 0).
(sw, sh) specifies the size of the image that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the image.
public final void drawImage(QPointF p, QImage image)
Draws the given image at the given p.
public final void drawImage(QPoint p, QImage image)
Draws the given image at the given p.
public final void drawImage(QRect targetRect, QImage image, QRect sourceRect, Qt.ImageConversionFlag... flags)
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device.
public final void drawImage(QRect targetRect, QImage image, QRect sourceRect)
Equivalent to drawImage(targetRect, image, sourceRect, Qt::AutoColor).
public final void drawImage(QRect targetRect, QImage image, QRect sourceRect, Qt.ImageConversionFlags flags)
Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device.
public final void drawImage(QRectF r, QImage image)
Draws the given image into the given r.
public final void drawLine(QLine line)
Draws a line defined by line.
public final void drawLine(QPoint p1, QPoint p2)
Draws a line from p1 to p2.
public final void drawLine(QPointF p1, QPointF p2)
Draws a line from p1 to p2.
public final void drawLine(int x1, int y1, int x2, int y2)
Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2).
public final void drawLine(QLineF line)
Draws a line defined by line.
![]() | QLineF line(10.0, 80.0, 90.0, 20.0); QPainter(this); painter.drawLine(line); |
public final void drawLinesFromPointsF(java.util.List<QPointF> pointPairs)
Draws a line for each pair of points in the vector pointPairs using the current pen. If there is an odd number of points in the array, the last point will be ignored.
public final void drawLinesF(java.util.List<QLineF> lines)
Draws the set of lines defined by the list lines using the current pen and brush.
public final void drawLines(java.util.List<QLine> lines)
Draws the set of lines defined by the list lines using the current pen and brush.
public final void drawLinesFromPoints(java.util.List<QPoint> pointPairs)
Draws a line for each pair of points in the vector pointPairs using the current pen.
public final void drawPath(QPainterPath path)
Draws the given painter path using the current pen for outline and the current brush for filling.
![]() | QPainterPath path; path.moveTo(20, 80); path.lineTo(20, 30); path.cubicTo(80, 0, 50, 50, 80, 80); QPainter painter(this); painter.drawPath(path); |
Painter Paths example
,
Vector Deformation demo
public final void drawPicture(QPoint p, QPicture picture)
Replays the given picture at the given p.
public final void drawPicture(QPointF p, QPicture picture)
Replays the given picture at the given p.
The QPicture class is a paint device that records and replays QPainter commands. A picture serializes the painter commands to an IO device in a platform-independent format. Everything that can be painted on a widget or pixmap can also be stored in a picture.
This function does exactly the same as QPicture::play() when called with p = QPoint(0, 0).
QPicture picture; QPointF point(10.0, 20.0) picture.load("drawing.pic"); QPainter painter(this); painter.drawPicture(0, 0, picture); |
public final void drawPicture(int x, int y, QPicture picture)
Draws the given picture at point (x, y).
public final void drawPie(int x, int y, int w, int h, int a, int alen)
Draws the pie defined by the rectangle beginning at (x, y) with the specified w and h, and the given a and alen.
public final void drawPie(QRect arg__1, int a, int alen)
Draws a pie defined by the given arg__1, a and and alen.
public final void drawPie(QRectF rect, int a, int alen)
Draws a pie defined by the given rect, a and and alen.
The pie is filled with the current brush.
The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.
![]() | QRectF rectangle(10.0, 20.0, 80.0, 60.0); int startAngle = 30 * 16; int spanAngle = 120 * 16; QPainter painter(this); painter.drawPie(rectangle, startAngle, spanAngle); |
public final void drawPixmap(QRect r, QPixmap pm)
Draws the given pm into the given r.
public final void drawPixmap(QPoint p, QPixmap pm, QRect sr)
Draws the rectangular portion sr of the given pm with its origin at the given p.
public final void drawPixmap(QRectF targetRect, QPixmap pixmap, QRectF sourceRect)
Draws the rectangular portion sourceRect of the given pixmap into the given targetRect in the paint device.
QRectF target(10.0, 20.0, 80.0, 60.0); QRectF source(0.0, 0.0, 70.0, 40.0); QPixmap pixmap(":myPixmap.png"); QPainter(this); painter.drawPixmap(target, image, source); |
If pixmap is a QBitmap it is drawn with the bits that are "set" using the pens color. If backgroundMode is Qt::OpaqueMode, the "unset" bits are drawn using the color of the background brush; if backgroundMode is Qt::TransparentMode, the "unset" bits are transparent. Drawing bitmaps with gradient or texture colors is not supported.
public final void drawPixmap(QPointF p, QPixmap pm)
Draws the given pm with its origin at the given p.
public final void drawPixmap(int x, int y, int w, int h, QPixmap pm, int sx, int sy, int sw, int sh)
Draws the rectangular portion with the origin (sx, sy), width sw and height sh, of the given pm , at the point (x, y), with a width of w and a height of h. If sw or sh are equal to zero the width/height of the pixmap is used and adjusted by the offset sx/sy;
public final void drawPixmap(int x, int y, QPixmap pm)
Draws the given pm at position (x, y).
public final void drawPixmap(QPoint p, QPixmap pm)
Draws the given pm with its origin at the given p.
public final void drawPixmap(QPointF p, QPixmap pm, QRectF sr)
Draws the rectangular portion sr of the given pm with its origin at the given p.
public final void drawPixmap(int x, int y, int w, int h, QPixmap pm)
Draws the pm into the rectangle at position (x, y) with the given w and h.
public final void drawPixmap(int x, int y, QPixmap pm, int sx, int sy, int sw, int sh)
Draws a pixmap at (x, y) by copying a part of the given pm into the paint device.
(x, y) specifies the top-left point in the paint device that is to be drawn onto. (sx, sy) specifies the top-left point in pm that is to be drawn. The default is (0, 0).
(sw, sh) specifies the size of the pixmap that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the pixmap.
public final void drawPixmap(QRect targetRect, QPixmap pixmap, QRect sourceRect)
Draws the rectangular portion sourceRect of the given pixmap into the given targetRect in the paint device.
public final void drawPoint(QPointF pt)
Draws a single point at the given pt using the current pen's color.
public final void drawPoint(int x, int y)
Draws a single point at position (x, y).
public final void drawPoint(QPoint p)
Draws a single point at the given p using the current pen's color.
public final void drawPoints(QPolygon points)
Draws the points in the vector points.
public final void drawPoints(QPolygonF points)
Draws the points in the vector points.
public final void drawPolygon(QPolygonF polygon)
Equivalent to drawPolygon(polygon, Qt::OddEvenFill).
public final void drawPolygon(QPolygonF polygon, Qt.FillRule fillRule)
Draws the polygon defined by the given polygon using the fill rule fillRule.
public final void drawPolygon(QPolygon polygon)
Equivalent to drawPolygon(polygon, Qt::OddEvenFill).
public final void drawPolygon(QPolygon polygon, Qt.FillRule fillRule)
Draws the polygon defined by the given polygon using the fill rule fillRule.
public final void drawPolyline(QPolygon polygon)
Draws the polyline defined by the given polygon using the current pen.
public final void drawPolyline(QPolygonF polyline)
Draws the polyline defined by the given polyline using the current pen.
public final void drawRect(int x1, int y1, int w, int h)
Draws a rectangle with upper left corner at (x1, y1) and with the given w and h.
public final void drawRect(QRectF rect)
Draws the current rect with the current pen and brush.
A filled rectangle has a size of rect.size(). A stroked rectangle has a size of rect.size() plus the pen width.
![]() | QRectF rectangle(10.0, 20.0, 80.0, 60.0); QPainter painter(this); painter.drawRect(rectangle); |
public final void drawRect(QRect rect)
Draws the current rect with the current pen and brush.
public final void drawRects(java.util.List<QRect> rectangles)
Draws the given rectangles using the current pen and brush.
public final void drawRectsF(java.util.List<QRectF> rectangles)
Draws the given rectangles using the current pen and brush.
public final void drawRoundRect(QRect r, int xround)
Equivalent to drawRoundRect(r, xround, 25).
public final void drawRoundRect(QRect r)
Equivalent to drawRoundRect(r, 25, 25).
public final void drawRoundRect(QRect r, int xround, int yround)
Draws the rectangle r with rounded corners.
public final void drawRoundRect(QRectF r, int xround)
Equivalent to drawRoundRect(r, xround, 25).
public final void drawRoundRect(QRectF r)
Equivalent to drawRoundRect(r, 25, 25).
public final void drawRoundRect(QRectF r, int xround, int yround)
Draws a rectangle r with rounded corners.
The xround and yround arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.
A filled rectangle has a size of r.size(). A stroked rectangle has a size of r.size() plus the pen width.
![]() | QRectF rectangle(10.0, 20.0, 80.0, 60.0); QPainter painter(this); painter.drawRoundRect(rectangle); |
public final void drawRoundRect(int x, int y, int w, int h, int arg__5)
Equivalent to drawRoundRect(x, y, w, h, arg__5, 25).
public final void drawRoundRect(int x, int y, int w, int h)
Equivalent to drawRoundRect(x, y, w, h, 25, 25).
public final void drawRoundRect(int x, int y, int w, int h, int arg__5, int arg__6)
Draws the rectangle x, y, w, h with rounded corners.
public final void drawText(QRectF r, java.lang.String text)
Equivalent to drawText(r, text, QTextOption()).
public final void drawText(QRectF r, java.lang.String text, QTextOption o)
Draws the given text in the r specified using the o to control its positioning and orientation.
public final void drawText(int x, int y, java.lang.String s)
Draws the given s at position (x, y), using the painter's currently defined text direction.
Note: The y-position is used as the baseline of the font.
public final void drawText(QPointF p, java.lang.String s)
Draws the given s with the currently defined text direction, beginning at the given p.
This function does not break text into multiple lines. Use the QPainter::drawText() overload that takes a rectangle instead if you want line breaking.
Note: The y-position is used as the baseline of the font.
public final void drawText(QPoint p, java.lang.String s)
Draws the given s with the currently defined text direction, beginning at the given p.
Note: The y-position is used as the baseline of the font.
public final void drawTextItem(int x, int y, QTextItem ti)
public final void drawTextItem(QPoint p, QTextItem ti)
public final void drawTextItem(QPointF p, QTextItem ti)
public final void drawTiledPixmap(QRectF rect, QPixmap pm)
Equivalent to drawTiledPixmap(rect, pm, QPointF()).
public final void drawTiledPixmap(QRectF rect, QPixmap pm, QPointF offset)
Draws a tiled pm, inside the given rect with its origin at the given offset.
Calling drawTiledPixmap is similar to calling drawPixmap several times to fill (tile) an area with a pixmap, but is potentially much more efficient depending on the underlying window system.
public final void drawTiledPixmap(int x, int y, int w, int h, QPixmap arg__5, int sx)
Equivalent to drawTiledPixmap(x, y, w, h, arg__5, sx, 0).
public final void drawTiledPixmap(int x, int y, int w, int h, QPixmap arg__5)
Equivalent to drawTiledPixmap(x, y, w, h, arg__5, 0, 0).
public final void drawTiledPixmap(int x, int y, int w, int h, QPixmap arg__5, int sx, int sy)
Draws a tiled arg__5 in the specified rectangle.
(x, y) specifies the top-left point in the paint device that is to be drawn onto; with the given w and h. (sx, sy) specifies the top-left point in the arg__5 that is to be drawn; this defaults to (0, 0).
public final void drawTiledPixmap(QRect arg__1, QPixmap arg__2)
Equivalent to drawTiledPixmap(arg__1, arg__2, QPoint()).
public final void drawTiledPixmap(QRect arg__1, QPixmap arg__2, QPoint arg__3)
Draws a tiled arg__2, inside the given arg__1 with its origin at the given arg__3.
public final boolean end()
Ends painting. Any resources used while painting are released. You don't normally need to call this since it is called by the destructor.
Returns true if the painter is no longer active; otherwise returns false.
public final void eraseRect(int x, int y, int w, int h)
Erases the area inside the rectangle beginning at (x, y) with the given w and h.
public final void eraseRect(QRectF arg__1)
Erases the area inside the given arg__1. Equivalent to calling
fillRect(rectangle, background()).
public final void eraseRect(QRect arg__1)
Erases the area inside the given arg__1.
public final void fillPath(QPainterPath path, QBrush brush)
Fills the given path using the given brush. The outline is not drawn.
Alternatively, you can specify a QColor instead of a QBrush; the QBrush constructor (taking a QColor argument) will automatically create a solid pattern brush.
public final void fillRect(QRect arg__1, QBrush arg__2)
Fills the given arg__1 with the given arg__2.
public final void fillRect(int x, int y, int w, int h, QBrush arg__5)
Fills the rectangle beginning at (x, y) with the given w and h, using the given arg__5.
public final void fillRect(QRectF arg__1, QBrush arg__2)
Fills the given arg__1 with the given arg__2.
Alternatively, you can specify a QColor instead of a QBrush; the QBrush constructor (taking a QColor argument) will automatically create a solid pattern brush.
public final QFont font()
Returns the currently set font used for drawing text.
Settings
public final QFontInfo fontInfo()
Returns the font info for the painter if the painter is active. Otherwise, the return value is undefined.
Settings
public final QFontMetrics fontMetrics()
Returns the font metrics for the painter if the painter is active. Otherwise, the return value is undefined.
Settings
public final boolean hasClipping()
Returns true if clipping has been set; otherwise returns false.
Clipping
public final void initFrom(QWidget widget)
Initializes the painters pen, background and font to the same as the given widget. Call this function after begin while the painter is active.
Settings
public final boolean isActive()
Returns true if begin has been called and end has not yet been called; otherwise returns false.
public final Qt.LayoutDirection layoutDirection()
Returns the layout direction used by the painter when drawing text.
Settings
public final double opacity()
Returns the opacity of the painter. The default value is 1.
public final QPaintEngine paintEngine()
Returns the paint engine that the painter is currently operating on if the painter is active; otherwise 0.
public final QPen pen()
Returns the painter's current pen.
Settings
public final QPainter.RenderHints renderHints()
Returns a flag that specifies the rendering hints that are set for this painter.
Quality
public final void resetMatrix()
Resets any transformations that were made using translate, scale, shear, rotate, setWorldMatrix, setViewport and setWindow.
It is advisable to use resetTransform instead of this function to preserve the properties of perspective transformations.
Transformations
public final void resetTransform()
Resets any transformations that were made using translate, scale, shear, rotate, setWorldTransform, setViewport and setWindow.
public final void restore()
Restores the current painter state (pops a saved state off the stack).
public final void rotate(double a)
Rotates the coordinate system the given a clockwise.
Transformations
public final void save()
Saves the current painter state (pushes the state onto a stack). A save must be followed by a corresponding restore; the end function unwinds the stack.
public final void scale(double sx, double sy)
Scales the coordinate system by (sx, sy).
Transformations
public final void setBackground(QBrush bg)
Sets the background brush of the painter to the given bg.
The background brush is the brush that is filled in when drawing opaque text, stippled lines and bitmaps. The background brush has no effect in transparent background mode (which is the default).
Settings
public final void setBackgroundMode(Qt.BGMode mode)
Sets the background mode of the painter to the given mode
Qt::TransparentMode (the default) draws stippled lines and text without setting the background pixels. Qt::OpaqueMode fills these space with the current background color.
Note that in order to draw a bitmap or pixmap transparently, you must use QPixmap::setMask().
Settings
public final void setBrush(QBrush brush)
Sets the painter's brush to the given brush.
The painter's brush defines how shapes are filled.
Settings
public final void setBrush(Qt.BrushStyle style)
Sets the painter's brush to black color and the specified style.
public final void setBrushOrigin(QPoint arg__1)
Sets the brush's origin to the given arg__1.
public final void setBrushOrigin(int x, int y)
Sets the brush's origin to point (x, y).
public final void setBrushOrigin(QPointF arg__1)
Sets the brush origin to arg__1.
The brush origin specifies the (0, 0) coordinate of the painter's brush. This setting only applies to pattern brushes and pixmap brushes.
Note that while the brushOrigin was necessary to adopt the parent's background for a widget in Qt 3, this is no longer the case since the Qt 4 painter doesn't paint the background unless you explicitly tell it to do so by setting the widget's autoFillBackground property to true.
Settings
public final void setClipPath(QPainterPath path)
Equivalent to setClipPath(path, Qt::ReplaceClip).
public final void setClipPath(QPainterPath path, Qt.ClipOperation op)
Enables clipping, and sets the clip path for the painter to the given path, with the clip op.
Note that the clip path is specified in logical (painter) coordinates.
Clipping
public final void setClipRect(QRectF arg__1)
Equivalent to setClipRect(arg__1, Qt::ReplaceClip).
public final void setClipRect(QRectF arg__1, Qt.ClipOperation op)
Enables clipping, and sets the clip region to the given arg__1 using the given clip op. The default operation is to replace the current clip rectangle.
Note that the clip rectangle is specified in logical (painter) coordinates.
Clipping
public final void setClipRect(int x, int y, int w, int h)
Equivalent to setClipRect(x, y, w, h, Qt::ReplaceClip).
public final void setClipRect(int x, int y, int w, int h, Qt.ClipOperation op)
Enables clipping, and sets the clip region to the rectangle beginning at (x, y) with the given w and h.
public final void setClipRect(QRect arg__1)
Equivalent to setClipRect(arg__1, Qt::ReplaceClip).
public final void setClipRect(QRect arg__1, Qt.ClipOperation op)
Enables clipping, and sets the clip region to the given arg__1 using the given clip op.
public final void setClipRegion(QRegion arg__1)
Equivalent to setClipRegion(arg__1, Qt::ReplaceClip).
public final void setClipRegion(QRegion arg__1, Qt.ClipOperation op)
Sets the clip region to the given arg__1 using the specified clip op. The default clip operation is to replace the current clip region.
Note that the clip region is given in logical coordinates.
Clipping
public final void setClipping(boolean enable)
Enables clipping if enable is true, or disables clipping if enable is false.
Clipping
public final void setCompositionMode(QPainter.CompositionMode mode)
Sets the composition mode to the given mode.
Warning: You can only set the composition mode for QPainter objects that operates on a QImage.
public final void setFont(QFont f)
Sets the painter's font to the given f.
This font is used by subsequent drawText functions. The text color is the same as the pen color.
If you set a font that isn't available, Qt finds a close match. font will return what you set using setFont and fontInfo returns the font actually being used (which may be the same).
Settings
public final void setLayoutDirection(Qt.LayoutDirection direction)
Sets the layout direction used by the painter when drawing text, to the specified direction.
Settings
public final void setOpacity(double opacity)
Sets the opacity of the painter to opacity. The value should be in the range 0.0 to 1.0, where 0.0 is fully transparent and 1.0 is fully opaque.
Opacity set on the painter will apply to all drawing operations individually.
public final void setPen(QColor color)
Sets the painter's pen to have style Qt::SolidLine, width 0 and the specified color.
public final void setPen(QPen pen)
Sets the painter's pen to be the given pen.
The pen defines how to draw lines and outlines, and it also defines the text color.
Settings
public final void setPen(Qt.PenStyle style)
Sets the painter's pen to have the given style, width 0 and black color.
public final void setRenderHint(QPainter.RenderHint hint)
Equivalent to setRenderHint(hint, true).
public final void setRenderHint(QPainter.RenderHint hint, boolean on)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
Quality
public final void setRenderHints(QPainter.RenderHints hints)
Equivalent to setRenderHints(hints, true).
public final void setRenderHints(QPainter.RenderHints hints, boolean on)
Sets the given render hints on the painter if on is true; otherwise clears the render hints.
Quality
public final void setTransform(QTransform transform)
Equivalent to setTransform(transform, false).
public final void setTransform(QTransform transform, boolean combine)
Sets the world transformation matrix. If combine is true, the specified transform is combined with the current matrix; otherwise it replaces the current matrix.
This function has been added for compatibility with setMatrix(), but as with setMatrix() the preferred method of setting a transformation on the painter is through setWorldTransform.
public final void setViewTransformEnabled(boolean enable)
Enables view transformations if enable is true, or disables view transformations if enable is false.
public final void setViewport(int x, int y, int w, int h)
Sets the painter's viewport rectangle to be the rectangle beginning at (x, y) with the given w and h.
public final void setViewport(QRect viewport)
Sets the painter's viewport rectangle to the given viewport, and enables view transformations.
The viewport rectangle is part of the view transformation. The viewport specifies the device coordinate system. Its sister, the window, specifies the logical coordinate system.
The default viewport rectangle is the same as the device's rectangle.
public final void setWindow(int x, int y, int w, int h)
Sets the painter's window to the rectangle beginning at (x, y) and the given w and h.
public final void setWindow(QRect window)
Sets the painter's window to the given window, and enables view transformations.
The window rectangle is part of the view transformation. The window specifies the logical coordinate system. Its sister, the viewport, specifies the device coordinate system.
The default window rectangle is the same as the device's rectangle.
public final void setWorldMatrix(QMatrix matrix)
Equivalent to setWorldMatrix(matrix, false).
public final void setWorldMatrix(QMatrix matrix, boolean combine)
Sets the transformation matrix to matrix and enables transformations.
Note: It is advisable to use setWorldTransform instead of this function to preserve the properties of perspective transformations.
If combine is true, then matrix is combined with the current transformation matrix; otherwise matrix replaces the current transformation matrix.
If matrix is the identity matrix and combine is false, this function calls setWorldMatrixEnabled(false). (The identity matrix is the matrix where QMatrix::m11() and QMatrix::m22() are 1.0 and the rest are 0.0.)
The following functions can transform the coordinate system without using a QMatrix:
They operate on the painter's worldMatrix and are implemented like this:
void QPainter::rotate(qreal angle) { QMatrix matrix; matrix.rotate(angle); setWorldMatrix(matrix, true); }
Note that when using setWorldMatrix function you should always have combine be true when you are drawing into a QPicture. Otherwise it may not be possible to replay the picture with additional transformations; using the translate, scale, etc. convenience functions is safe.
For more information about the coordinate system, transformations and window-viewport conversion, see The Coordinate System documentation.
public final void setWorldMatrixEnabled(boolean enabled)
Enables transformations if enabled is true, or disables transformations if enabled is false. The world transformation matrix is not changed.
Transformations
public final void setWorldTransform(QTransform matrix)
Equivalent to setWorldTransform(matrix, false).
public final void setWorldTransform(QTransform matrix, boolean combine)
Sets the world transformation matrix. If combine is true, the specified matrix is combined with the current matrix; otherwise it replaces the current matrix.
public final void shear(double sh, double sv)
Shears the coordinate system by (sh, sv).
Transformations
public final void strokePath(QPainterPath path, QPen pen)
Draws the outline (strokes) the path path with the pen specified by pen
Drawing
public final boolean testRenderHint(QPainter.RenderHint hint)
Returns true if hint is set; otherwise returns false.
public final QTransform transform()
Returns the world transformation matrix.
public final void translate(double dx, double dy)
Translates the coordinate system by the vector (dx, dy).
public final void translate(QPointF offset)
Translates the coordinate system by the given offset; i.e. the given offset is added to points.
Transformations
public final void translate(QPoint offset)
Translates the coordinate system by the given offset.
public final boolean viewTransformEnabled()
Returns true if view transformation is enabled; otherwise returns false.
public final QRect viewport()
Returns the viewport rectangle.
public final QRect window()
Returns the window rectangle.
public final QMatrix worldMatrix()
Returns the world transformation matrix.
It is advisable to use worldTransform because worldMatrix does not preserve the properties of perspective transformations.
Transformations
,
The Coordinate Systempublic final boolean worldMatrixEnabled()
Returns true if world transformation is enabled; otherwise returns false.
public final QTransform worldTransform()
Returns the world transformation matrix.
public static void restoreRedirected(QPaintDeviceInterface device)
Restores the previous redirection for the given device after a call to setRedirected.
public static void setRedirected(QPaintDeviceInterface device, QPaintDeviceInterface replacement)
Equivalent to setRedirected(device, replacement, QPoint()).
public static void setRedirected(QPaintDeviceInterface device, QPaintDeviceInterface replacement, QPoint offset)
Redirects all paint commands for the given paint device, to the replacement device. The optional point offset defines an offset within the source device.
The redirection will not be effective until the begin function has been called; make sure to call end for the given device's painter (if any) before redirecting. Call restoreRedirected to restore the previous redirection.
In general, you'll probably find that calling QPixmap::grabWidget() or QPixmap::grabWindow() is an easier solution.
public static QPainter fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public void setBrush(QColor color)
public void setBrush(QGradient gradient)
public void setBrush(QPixmap pm)
public final void drawText(QRect rectangle, int flags, java.lang.String text, QRect boundingRect)
The boundingRect (if not null) is set to the actual bounding rectangle of the output. The flags argument is a bitwise OR of Qt.AlignmentFlags.
public final void drawText(QRect rectangle, int flags, java.lang.String text)
public final void drawText(QRectF rectangle, int flags, java.lang.String text, QRectF boundingRect)
The boundingRect (if not null) is set to the actual bounding rectangle of the output. The flags argument is a bitwise OR of Qt.AlignmentFlags.
public final void drawText(QRectF rectangle, int flags, java.lang.String text)
public final void drawText(int x, int y, int width, int height, int flags, java.lang.String text, QRect boundingRect)
The boundingRect (if not null) is set to the actual bounding rectangle of the output. The flags argument is a bitwise OR of the following flags:
public final void drawText(int x, int y, int width, int height, int flags, java.lang.String text)
public static QPaintDeviceInterface redirected(QPaintDeviceInterface device, QPoint offset)
public boolean begin(QWidget widget)
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |