|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.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:
@Override protected void paintEvent(QPaintEvent e) { QPainter painter = new QPainter(this); painter.setPen(QColor.blue); painter.setFont(new QFont("Arial", 30)); painter.drawText(rect(), Qt.AlignmentFlag.AlignCenter.value(), "Qt"); painter.end(); }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.
font()
is the font used for drawing text. If the painter isActive()
, you can retrieve information about the currently set font, and its metrics, using the fontInfo()
and fontMetrics()
functions respectively.brush()
defines the color or pattern that is used for filling shapes.pen()
defines the color or stipple that is used for drawing lines or boundaries.backgroundMode()
defines whether there is a background()
or not, i.e it is either Qt::OpaqueMode
or Qt::TransparentMode
.background()
only applies when backgroundMode()
is Qt::OpaqueMode
and pen()
is a stipple. In that case, it describes the color of the background pixels in the stipple.brushOrigin()
defines the origin of the tiled brushes, normally the origin of widget's background.viewport()
, window()
, worldMatrix()
make up the painter's coordinate transformation system. For more information, see the Coordinate Transformations section and the The Coordinate System documentation.hasClipping()
tells whether the painter clips at all. (The paint device clips, too.) If the painter clips, it clips to clipRegion()
.layoutDirection()
defines the layout direction used by the painter when drawing text.viewTransformEnabled()
tells whether view transformation is enabled.QWidget::font()
. The QPainter::begin()
function (or equivalently the QPainter constructor) copies these attributes from the paint device. You can at any time save the QPainter's state by calling the save()
function which saves all the available settings on an internal stack. The restore()
function pops them back.Drawing
QPainter provides functions to draw most primitives: drawPoint()
, drawPoints()
, drawLine()
, drawRect()
, drawRoundedRect()
, drawEllipse()
, drawArc()
, drawPie()
, drawChord()
, drawPolyline()
, drawPolygon()
, drawConvexPolygon()
and drawCubicBezier(). The two convenience functions, drawRects()
and drawLines()
, draw the given number of rectangles or lines in the given array of QRects
or 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. |
QPainterPath
and drawing it using drawPath()
. Painter Paths example The The Painter Paths example shows how painter paths can be used to build complex shapes for rendering. | ![]() |
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.
![]() | ![]() | ![]() |
drawPixmap()
, drawImage()
and drawTiledPixmap()
. Both drawPixmap()
and drawImage()
produce the same result, except that drawPixmap()
is faster on-screen while drawImage()
may be faster on a QPrinter
or other devices. Text drawing is done using drawText()
. When you need fine-grained positioning, boundingRect()
tells you where a given drawText()
command will draw.
There is a drawPicture()
function that draws the contents of an entire QPicture
. The drawPicture()
function is the only function that disregards all the painter's settings as QPicture
has its own settings.Rendering Quality
To get the optimal rendering result using QPainter, you should use the platform independent QImage
as paint device; i.e. using QImage
will ensure that the result has an identical pixel representation on any platform.
The QPainter class also provides a means of controlling the rendering quality through its RenderHint
enum and the support for floating point precision: All the functions for drawing primitives has a floating point version. These are often used in combination with the 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. |
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.Coordinate Transformations
Normally, the QPainter operates on the device's own coordinate system (usually pixels), but QPainter has good support for coordinate transformations.
![]() | ![]() | ![]() | ![]() |
rotate() | scale() | translate() |
---|
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. | ![]() |
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.Clipping
QPainter can clip any drawing operation to a rectangle, a region, or a vector path. The current clip is available using the functions clipRegion()
and clipPath()
. Whether paths or regions are preferred (faster) depends on the underlying paintEngine()
. For example, the QImage
paint engine prefers paths while the X11 paint engine prefers regions. Setting a clip is done in the painters logical coordinates.
After QPainter's clipping, the paint device may also clip. For example, most widgets clip away the pixels used by child widgets, and most printers clip away an area near the edges of the paper. This additional clipping is not reflected by the return value of clipRegion()
or hasClipping()
.Composition Modes
QPainter provides the CompositionMode
enum which defines the Porter-Duff rules for digital image compositing; it describes a model for combining the pixels in one image, the source, with the pixels in another image, the destination.
The two most common forms of composition are 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. |
QPaintDevice
, QPaintEngine
, QtSvg Module, and Basic 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
|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QPainter()
Constructs a painter. |
|
QPainter(QPaintDeviceInterface arg__1)
Constructs a painter that begins painting the paint device 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 device 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 rectangle with the specified flags using the currently set font() ; i.e the function tells you where the drawText() function will draw when given the same arguments. |
QRectF |
boundingRect(QRectF rect,
java.lang.String text)
Instead of specifying flags as a bitwise OR of the Qt::AlignmentFlag and Qt::TextFlag , this overloaded function takes an option argument. |
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 option 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 rectangle 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 width and height, and the given startAngle and spanAngle. |
void |
drawArc(QRectF rect,
int a,
int alen)
Draws the arc defined by the given rectangle, startAngle and spanAngle. |
void |
drawArc(QRect arg__1,
int a,
int 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 width and height, and the given startAngle and spanAngle. |
void |
drawChord(QRectF rect,
int a,
int alen)
Draws the chord defined by the given rectangle, startAngle and spanAngle. |
void |
drawChord(QRect arg__1,
int a,
int 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 width and height. |
void |
drawEllipse(QPointF center,
double rx,
double ry)
Draws the ellipse positioned at center with radii rx and ry. |
void |
drawEllipse(QPoint center,
int rx,
int ry)
Draws the ellipse positioned at center with radii rx and ry. |
void |
drawEllipse(QRect r)
Draws the ellipse defined by the given rectangle. |
void |
drawEllipse(QRectF r)
Draws the ellipse defined by the given rectangle. |
void |
drawImage(int x,
int y,
QImage image)
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)
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)
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)
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)
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.ImageConversionFlag[] flags)
|
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 point. |
void |
drawImage(QPointF p,
QImage image,
QRectF sr)
Draws the rectangular portion source of the given image with its origin at the given point. |
void |
drawImage(QPointF p,
QImage image,
QRectF sr,
Qt.ImageConversionFlag[] flags)
|
void |
drawImage(QPointF p,
QImage image,
QRectF sr,
Qt.ImageConversionFlags flags)
Draws the rectangular portion source of the given image with its origin at the given point. |
void |
drawImage(QPoint p,
QImage image)
|
void |
drawImage(QPoint p,
QImage image,
QRect sr)
Draws the rectangular portion source of the given image with its origin at the given point. |
void |
drawImage(QPoint p,
QImage image,
QRect sr,
Qt.ImageConversionFlag[] flags)
|
void |
drawImage(QPoint p,
QImage image,
QRect sr,
Qt.ImageConversionFlags flags)
|
void |
drawImage(QRectF r,
QImage image)
Draws the given image into the given rectangle. |
void |
drawImage(QRectF targetRect,
QImage image,
QRectF sourceRect)
Draws the rectangular portion source of the given image into the target rectangle in the paint device. |
void |
drawImage(QRectF targetRect,
QImage image,
QRectF sourceRect,
Qt.ImageConversionFlag[] flags)
|
void |
drawImage(QRectF targetRect,
QImage image,
QRectF sourceRect,
Qt.ImageConversionFlags flags)
Draws the rectangular portion source of the given image into the target rectangle in the paint device. |
void |
drawImage(QRect r,
QImage image)
|
void |
drawImage(QRect targetRect,
QImage image,
QRect sourceRect)
Draws the rectangular portion source of the given image into the target rectangle in the paint device. |
void |
drawImage(QRect targetRect,
QImage image,
QRect sourceRect,
Qt.ImageConversionFlag[] flags)
|
void |
drawImage(QRect targetRect,
QImage image,
QRect sourceRect,
Qt.ImageConversionFlags flags)
|
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 lines)
Draws the set of lines defined by the list lines using the current pen and brush. |
void |
drawLinesF(java.util.List lines)
Draws the set of lines defined by the list lines using the current pen and brush. |
void |
drawLinesFromPoints(java.util.List pointPairs)
Draws a line for each pair of points in the vector pointPairs using the current pen. |
void |
drawLinesFromPointsF(java.util.List 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 point. |
void |
drawPicture(QPoint p,
QPicture picture)
|
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 width and height, and the given startAngle and spanAngle. |
void |
drawPie(QRectF rect,
int a,
int alen)
Draws a pie defined by the given rectangle, startAngle and and spanAngle. |
void |
drawPie(QRect arg__1,
int a,
int alen)
|
void |
drawPixmap(int x,
int y,
int w,
int h,
QPixmap pm)
Draws the pixmap into the rectangle at position (x, y) with the given width and height. |
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 pixmap , 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 pixmap 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 pixmap into the paint device. |
void |
drawPixmap(QPointF p,
QPixmap pm)
Draws the given pixmap with its origin at the given point. |
void |
drawPixmap(QPointF p,
QPixmap pm,
QRectF sr)
Draws the rectangular portion source of the given pixmap with its origin at the given point. |
void |
drawPixmap(QPoint p,
QPixmap pm)
|
void |
drawPixmap(QPoint p,
QPixmap pm,
QRect sr)
Draws the rectangular portion source of the given pixmap with its origin at the given point. |
void |
drawPixmap(QRectF targetRect,
QPixmap pixmap,
QRectF sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device. |
void |
drawPixmap(QRect r,
QPixmap pm)
Draws the given pixmap into the given rectangle. |
void |
drawPixmap(QRect targetRect,
QPixmap pixmap,
QRect sourceRect)
Draws the rectangular portion source of the given pixmap into the given target 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 position using the current pen's color. |
void |
drawPoint(QPointF pt)
Draws a single point at the given position 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)
Draws the polygon defined by the given points using the fill rule fillRule. |
void |
drawPolygon(QPolygonF polygon)
Draws the polygon defined by the given points using the fill rule fillRule. |
void |
drawPolygon(QPolygonF polygon,
Qt.FillRule fillRule)
Draws the polygon defined by the given points using the fill rule fillRule. |
void |
drawPolygon(QPolygon polygon,
Qt.FillRule fillRule)
|
void |
drawPolyline(QPolygon polygon)
Draws the polyline defined by the given points using the current pen. |
void |
drawPolyline(QPolygonF polyline)
Draws the polyline defined by the given points using the current pen. |
void |
drawRect(int x1,
int y1,
int w,
int h)
Draws a rectangle with upper left corner at (x, y) and with the given width and height. |
void |
drawRect(QRect rect)
Draws the current rectangle with the current pen and brush. |
void |
drawRect(QRectF rect)
Draws the current rectangle with the current pen and brush. |
void |
drawRects(java.util.List rectangles)
Draws the given rectangles using the current pen and brush. |
void |
drawRectsF(java.util.List rectangles)
Draws the given rectangles using the current pen and brush. |
void |
drawRoundedRect(int x,
int y,
int w,
int h,
double xRadius,
double yRadius)
Draws the given rectangle x, y, w, h with rounded corners. |
void |
drawRoundedRect(int x,
int y,
int w,
int h,
double xRadius,
double yRadius,
Qt.SizeMode mode)
Draws the given rectangle x, y, w, h with rounded corners. |
void |
drawRoundedRect(QRect rect,
double xRadius,
double yRadius)
|
void |
drawRoundedRect(QRect rect,
double xRadius,
double yRadius,
Qt.SizeMode mode)
|
void |
drawRoundedRect(QRectF rect,
double xRadius,
double yRadius)
Draws the given rectangle rect with rounded corners. |
void |
drawRoundedRect(QRectF rect,
double xRadius,
double yRadius,
Qt.SizeMode mode)
Draws the given rectangle rect with rounded corners. |
void |
drawRoundRect(int x,
int y,
int w,
int h)
Draws the rectangle x, y, w, h with rounded corners. |
void |
drawRoundRect(int x,
int y,
int w,
int h,
int arg__5)
Draws the rectangle x, y, w, h with rounded corners. |
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)
Draws the rectangle r with rounded corners. |
void |
drawRoundRect(QRectF r)
Draws a rectangle r with rounded corners. |
void |
drawRoundRect(QRectF r,
int xround)
Draws the rectangle r with rounded corners. |
void |
drawRoundRect(QRectF r,
int xround,
int yround)
Draws the rectangle r with rounded corners. |
void |
drawRoundRect(QRect r,
int xround)
|
void |
drawRoundRect(QRect r,
int xround,
int yround)
|
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 text at position (x, y), using the painter's currently defined text direction. |
void |
drawText(QPointF p,
java.lang.String s)
Draws the given text with the currently defined text direction, beginning at the given position. |
void |
drawText(QPoint p,
java.lang.String s)
|
void |
drawText(QRectF rectangle,
int flags,
java.lang.String text)
This is an overloaded function 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)
Draws the given text in the rectangle specified using the option to control its positioning and orientation. |
void |
drawText(QRectF r,
java.lang.String text,
QTextOption o)
Draws the given text in the rectangle specified using the option to control its positioning and orientation. |
void |
drawText(QRect rectangle,
int flags,
java.lang.String text)
|
void |
drawText(QRect rectangle,
int flags,
java.lang.String text,
QRect boundingRect)
Draws the given text within the provided rectangle. |
void |
drawTextItem(QPoint p,
QTextItem ti)
|
void |
drawTiledPixmap(int x,
int y,
int w,
int h,
QPixmap arg__5)
Draws a tiled pixmap in the specified rectangle. |
void |
drawTiledPixmap(int x,
int y,
int w,
int h,
QPixmap arg__5,
int sx)
Draws a tiled pixmap in the specified rectangle. |
void |
drawTiledPixmap(int x,
int y,
int w,
int h,
QPixmap arg__5,
int sx,
int sy)
Draws a tiled pixmap in the specified rectangle. |
void |
drawTiledPixmap(QRectF rect,
QPixmap pm)
Draws a tiled pixmap, inside the given rectangle with its origin at the given position. |
void |
drawTiledPixmap(QRectF rect,
QPixmap pm,
QPointF offset)
Draws a tiled pixmap, inside the given rectangle with its origin at the given position. |
void |
drawTiledPixmap(QRect arg__1,
QPixmap arg__2)
|
void |
drawTiledPixmap(QRect arg__1,
QPixmap arg__2,
QPoint arg__3)
Draws a tiled pixmap, inside the given rectangle with its origin at the given position. |
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 width and height. |
void |
eraseRect(QRect arg__1)
Erases the area inside the given rectangle. |
void |
eraseRect(QRectF arg__1)
Erases the area inside the given rectangle. |
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 width and height, using the given brush. |
void |
fillRect(QRectF arg__1,
QBrush arg__2)
Fills the given rectangle with the given brush. |
void |
fillRect(QRect arg__1,
QBrush 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. |
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 angle 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 brush. |
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 position. |
void |
setBrushOrigin(QPointF arg__1)
Sets the brush origin to position. |
void |
setClipPath(QPainterPath path)
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation. |
void |
setClipPath(QPainterPath path,
Qt.ClipOperation op)
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation. |
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)
Enables clipping, and sets the clip region to the rectangle beginning at (x, y) with the given width and height. |
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 width and height. |
void |
setClipRect(QRect arg__1)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation. |
void |
setClipRect(QRectF arg__1)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation. |
void |
setClipRect(QRectF arg__1,
Qt.ClipOperation op)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation. |
void |
setClipRect(QRect arg__1,
Qt.ClipOperation op)
|
void |
setClipRegion(QRegion arg__1)
Sets the clip region to the given region using the specified clip operation. |
void |
setClipRegion(QRegion arg__1,
Qt.ClipOperation op)
Sets the clip region to the given region using the specified clip operation. |
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 font. |
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)
Redirects all paint commands for the given paint device, to the replacement device. |
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)
Sets the given render hint on the painter if on is true; otherwise clears the render hint. |
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)
Sets the given render hints on the painter if on is true; otherwise clears the render hints. |
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)
Sets the world transformation matrix. |
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 width and height. |
void |
setViewport(QRect viewport)
Sets the painter's viewport rectangle to the given rectangle, 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 width and height. |
void |
setWindow(QRect window)
Sets the painter's window to the given rectangle, and enables view transformations. |
void |
setWorldMatrix(QMatrix matrix)
Sets the transformation matrix to matrix and enables transformations. |
void |
setWorldMatrix(QMatrix matrix,
boolean combine)
Sets the transformation matrix to matrix and enables transformations. |
void |
setWorldMatrixEnabled(boolean enabled)
Enables transformations if enable is true, or disables transformations if enable is false. |
void |
setWorldTransform(QTransform matrix)
Sets the world transformation matrix. |
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. |
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, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, 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()
begin()
, and end()
.
public QPainter(QPaintDeviceInterface arg__1)
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()
:
@Override protected void paintEvent(QPaintEvent e) { QPainter p = new QPainter(); p.begin(this); p.drawLine(line); // drawing code p.end(); }The same example using this constructor:
@Override protected void paintEvent(QPaintEvent e) { QPainter p = new QPainter(this); p.drawLine(line); // drawing code p.end(); }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. begin()
, and end()
.
public QPainter(QWidget widget)
Method Detail |
---|
public final QBrush background()
setBackground()
, and Settings.
public final Qt.BGMode backgroundMode()
setBackgroundMode()
, and Settings.
public final boolean begin(QPaintDeviceInterface arg__1)
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(null); // impossible - paint device cannot be null QPixmap image = new QPixmap(0, 0); painter.begin(image); // impossible - image.isNull() == true; painter.begin(myWidget); painter2.begin(myWidget); // impossible - only one painter at a timeNote 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.
end()
, and QPainter().
public final QRect boundingRect(QRect rect, int flags, java.lang.String text)
font()
.
public final QRectF boundingRect(QRectF rect, java.lang.String text)
Qt::AlignmentFlag
and Qt::TextFlag
, this overloaded function takes an option argument. The QTextOption
class provides a description of general rich text properties. QTextOption
.
public final QRectF boundingRect(QRectF rect, java.lang.String text, QTextOption o)
Qt::AlignmentFlag
and Qt::TextFlag
, this overloaded function takes an option argument. The QTextOption
class provides a description of general rich text properties. QTextOption
.
public final QRectF boundingRect(QRectF rect, int flags, java.lang.String text)
font()
; i.e the function tells you where the drawText()
function will draw when given the same arguments. If the text does not fit within the given rectangle using the specified flags, the function returns the required rectangle.
The flags argument is a bitwise OR of the following flags:
If several of the horizontal or several of the vertical alignment flags are set, the resulting alignment is undefined.drawText()
, Qt::Alignment, and Qt::TextFlag
.
public final QRect boundingRect(int x, int y, int w, int h, int flags, java.lang.String text)
public final QBrush brush()
QPainter::setBrush()
, and Settings.
public final QPoint brushOrigin()
setBrushOrigin()
, and Settings.
public final QPainterPath clipPath()
setClipPath()
, clipRegion()
, and setClipping()
.
public final QRegion clipRegion()
setClipRegion()
, clipPath()
, and setClipping()
.
public final QMatrix combinedMatrix()
It is advisable to use combinedTransform()
instead of this function to preserve the properties of perspective transformations.
setWorldMatrix()
, setWindow()
, and setViewport()
.
public final QTransform combinedTransform()
setWorldMatrix()
, setWindow()
, and setViewport()
.
public final QPainter.CompositionMode compositionMode()
CompositionMode
, and setCompositionMode()
.
public final QPaintDeviceInterface device()
isActive()
.
public final QMatrix deviceMatrix()
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.
worldMatrix()
, and QPaintEngine::hasFeature()
.
public final QTransform deviceTransform()
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.
worldTransform()
, and QPaintEngine::hasFeature()
.
public final void drawArc(QRect arg__1, int a, int alen)
public final void drawArc(QRectF rect, int a, int alen)
public final void drawArc(int x, int y, int w, int h, int a, int alen)
public final void drawChord(QRect arg__1, int a, int alen)
public final void drawChord(QRectF rect, int a, int alen)
public final void drawChord(int x, int y, int w, int h, int a, int alen)
public final void drawConvexPolygon(QPolygon polygon)
public final void drawConvexPolygon(QPolygonF polygon)
public final void drawEllipse(QPoint center, int rx, int ry)
public final void drawEllipse(QPointF center, double rx, double ry)
public final void drawEllipse(QRect r)
public final void drawEllipse(QRectF r)
A filled ellipse has a size of rectangle.size()
. A stroked ellipse has a size of rectangle.size()
plus the pen width.
![]() | QRectF rectangle = new QRectF(10.0, 20.0, 80.0, 60.0); QPainter painter = new QPainter(this); painter.drawEllipse(rectangle); painter.end(); |
drawPie()
, and The Coordinate System.
public final void drawEllipse(int x, int y, int w, int h)
public final void drawImage(QPoint p, QImage image)
public final void drawImage(QPoint p, QImage image, QRect sr, Qt.ImageConversionFlag[] flags)
public final void drawImage(QPoint p, QImage image, QRect sr)
public final void drawImage(QPoint p, QImage image, QRect sr, Qt.ImageConversionFlags flags)
public final void drawImage(QPointF p, QImage image)
public final void drawImage(QPointF p, QImage image, QRectF sr, Qt.ImageConversionFlag[] flags)
public final void drawImage(QPointF p, QImage image, QRectF sr)
public final void drawImage(QPointF p, QImage image, QRectF sr, Qt.ImageConversionFlags flags)
public final void drawImage(QRect r, QImage image)
public final void drawImage(QRect targetRect, QImage image, QRect sourceRect, Qt.ImageConversionFlag[] flags)
public final void drawImage(QRect targetRect, QImage image, QRect sourceRect)
Note: The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
public final void drawImage(QRect targetRect, QImage image, QRect sourceRect, Qt.ImageConversionFlags flags)
public final void drawImage(QRectF r, QImage image)
Note: The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
public final void drawImage(QRectF targetRect, QImage image, QRectF sourceRect, Qt.ImageConversionFlag[] flags)
public final void drawImage(QRectF targetRect, QImage image, QRectF sourceRect)
Note: The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
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 = new QRectF(10.0, 20.0, 80.0, 60.0); QRectF source = new QRectF(0.0, 0.0, 70.0, 40.0); QImage image = new QImage("classpath:/images/myImage.png"); QPainter painter = new QPainter(this); painter.drawImage(target, image, source); painter.end(); |
drawPixmap()
.
public final void drawImage(QRectF targetRect, QImage image, QRectF sourceRect, Qt.ImageConversionFlags flags)
Note: The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
public final void drawImage(int x, int y, QImage image, int sx, int sy, int sw, int sh, Qt.ImageConversionFlag[] flags)
public final void drawImage(int x, int y, QImage image, int sx, int sy, int sw, int sh)
(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)
(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)
(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)
(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)
(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, Qt.ImageConversionFlags flags)
(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 drawLine(QLine line)
public final void drawLine(QLineF line)
![]() | QLineF line = new QLineF(10.0, 80.0, 90.0, 20.0); QPainter painter = new QPainter(this); painter.drawLine(line); painter.end(); |
drawLines()
, drawPolyline()
, and The Coordinate System.
public final void drawLine(QPoint p1, QPoint p2)
public final void drawLine(QPointF p1, QPointF p2)
public final void drawLine(int x1, int y1, int x2, int y2)
public final void drawLines(java.util.List lines)
public final void drawLinesF(java.util.List lines)
public final void drawLinesFromPoints(java.util.List pointPairs)
public final void drawLinesFromPointsF(java.util.List pointPairs)
public final void drawPath(QPainterPath path)
![]() | QPainterPath path = new QPainterPath(); path.moveTo(20, 80); path.lineTo(20, 30); path.cubicTo(80, 0, 50, 50, 80, 80); QPainter painter = new QPainter(this); painter.drawPath(path); painter.end(); |
public final void drawPicture(QPoint p, QPicture picture)
public final void drawPicture(QPointF p, QPicture picture)
public final void drawPicture(int x, int y, QPicture picture)
public final void drawPie(QRect arg__1, int a, int alen)
public final void drawPie(QRectF rect, int a, int alen)
public final void drawPie(int x, int y, int w, int h, int a, int alen)
public final void drawPixmap(QPoint p, QPixmap pm)
public final void drawPixmap(QPoint p, QPixmap pm, QRect sr)
public final void drawPixmap(QPointF p, QPixmap pm)
public final void drawPixmap(QPointF p, QPixmap pm, QRectF sr)
public final void drawPixmap(QRect r, QPixmap pm)
Note: The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
public final void drawPixmap(QRect targetRect, QPixmap pixmap, QRect sourceRect)
Note: The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
public final void drawPixmap(QRectF targetRect, QPixmap pixmap, QRectF sourceRect)
Note: The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
QRectF target = new QRectF(10.0, 20.0, 80.0, 60.0); QRectF source = new QRectF(0.0, 0.0, 70.0, 40.0); QPixmap pixmap = new QPixmap("classpath:myPixmap.png"); QPainter painter = new QPainter(this); painter.drawPixmap(target, pixmap, source); painter.end(); |
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. drawImage()
.
public final void drawPixmap(int x, int y, QPixmap pm)
public final void drawPixmap(int x, int y, QPixmap pm, int sx, int sy, int sw, int sh)
(x, y) specifies the top-left point in the paint device that is to be drawn onto. (sx, sy) specifies the top-left point in pixmap that is to be drawn. The default is (0, 0).
(sw, sh) specifies the size of the pixmap that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the pixmap.
public final void drawPixmap(int x, int y, int w, int h, QPixmap pm)
public final void drawPixmap(int x, int y, int w, int h, QPixmap pm, int sx, int sy, int sw, int sh)
public final void drawPoint(QPoint p)
public final void drawPoint(QPointF pt)
public final void drawPoint(int x, int y)
public final void drawPoints(QPolygon points)
public final void drawPoints(QPolygonF points)
public final void drawPolygon(QPolygon polygon)
public final void drawPolygon(QPolygon polygon, Qt.FillRule fillRule)
public final void drawPolygon(QPolygonF polygon)
public final void drawPolygon(QPolygonF polygon, Qt.FillRule fillRule)
public final void drawPolyline(QPolygon polygon)
public final void drawPolyline(QPolygonF polyline)
public final void drawRect(QRect rect)
public final void drawRect(QRectF rect)
A filled rectangle has a size of rectangle.size(). A stroked rectangle has a size of rectangle.size() plus the pen width.
![]() | QRectF rectangle = new QRectF(10.0, 20.0, 80.0, 60.0); QPainter painter = new QPainter(this); painter.drawRect(rectangle); painter.end(); |
drawRects()
, drawPolygon()
, and The Coordinate System.
public final void drawRect(int x1, int y1, int w, int h)
public final void drawRects(java.util.List rectangles)
public final void drawRectsF(java.util.List rectangles)
public final void drawRoundRect(QRect r, int xround)
public final void drawRoundRect(QRect r)
public final void drawRoundRect(QRect r, int xround, int yround)
public final void drawRoundRect(QRectF r, int xround)
public final void drawRoundRect(QRectF r)
The xRnd and yRnd arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.
A filled rectangle has a size of r.size(). A stroked rectangle has a size of r.size() plus the pen width.
drawRoundedRect()
.
public final void drawRoundRect(QRectF r, int xround, int yround)
public final void drawRoundRect(int x, int y, int w, int h, int arg__5)
public final void drawRoundRect(int x, int y, int w, int h)
public final void drawRoundRect(int x, int y, int w, int h, int arg__5, int arg__6)
public final void drawRoundedRect(QRect rect, double xRadius, double yRadius)
public final void drawRoundedRect(QRect rect, double xRadius, double yRadius, Qt.SizeMode mode)
public final void drawRoundedRect(QRectF rect, double xRadius, double yRadius)
public final void drawRoundedRect(QRectF rect, double xRadius, double yRadius, Qt.SizeMode mode)
public final void drawRoundedRect(int x, int y, int w, int h, double xRadius, double yRadius)
public final void drawRoundedRect(int x, int y, int w, int h, double xRadius, double yRadius, Qt.SizeMode mode)
public final void drawText(QPoint p, java.lang.String s)
public final void drawText(QPointF p, java.lang.String s)
By default, QPainter draws text anti-aliased.
Note: The y-position is used as the baseline of the font.
public final void drawText(QRectF r, java.lang.String text)
By default, QPainter draws text anti-aliased.
Note: The y-coordinate of rectangle is used as the top of the font.
public final void drawText(QRectF r, java.lang.String text, QTextOption o)
By default, QPainter draws text anti-aliased.
Note: The y-coordinate of rectangle is used as the top of the font.
public final void drawText(int x, int y, java.lang.String s)
By default, QPainter draws text anti-aliased.
Note: The y-position is used as the baseline of the font.
public final void drawTextItem(QPoint p, QTextItem ti)
public final void drawTiledPixmap(QRect arg__1, QPixmap arg__2)
public final void drawTiledPixmap(QRect arg__1, QPixmap arg__2, QPoint arg__3)
public final void drawTiledPixmap(QRectF rect, QPixmap pm)
public final void drawTiledPixmap(QRectF rect, QPixmap pm, QPointF 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.
drawPixmap()
.
public final void drawTiledPixmap(int x, int y, int w, int h, QPixmap arg__5, int sx)
(x, y) specifies the top-left point in the paint device that is to be drawn onto; with the given width and height. (sx, sy) specifies the top-left point in the pixmap that is to be drawn; this defaults to (0, 0).
public final void drawTiledPixmap(int x, int y, int w, int h, QPixmap arg__5)
(x, y) specifies the top-left point in the paint device that is to be drawn onto; with the given width and height. (sx, sy) specifies the top-left point in the pixmap that is to be drawn; this defaults to (0, 0).
public final void drawTiledPixmap(int x, int y, int w, int h, QPixmap arg__5, int sx, int sy)
(x, y) specifies the top-left point in the paint device that is to be drawn onto; with the given width and height. (sx, sy) specifies the top-left point in the pixmap that is to be drawn; this defaults to (0, 0).
public final boolean end()
Returns true if the painter is no longer active; otherwise returns false.
begin()
, and isActive()
.
public final void eraseRect(QRect arg__1)
public final void eraseRect(QRectF arg__1)
fillRect(rectangle, background());
fillRect()
.
public final void eraseRect(int x, int y, int w, int h)
public final void fillPath(QPainterPath path, QBrush brush)
Alternatively, you can specify a QColor
instead of a QBrush
; the QBrush
constructor (taking a QColor
argument) will automatically create a solid pattern brush.
drawPath()
.
public final void fillRect(QRect arg__1, QBrush arg__2)
public final void fillRect(QRectF arg__1, QBrush arg__2)
public final void fillRect(int x, int y, int w, int h, QBrush arg__5)
public final QFont font()
setFont()
, drawText()
, and Settings.
public final QFontInfo fontInfo()
font()
, isActive()
, and Settings.
public final QFontMetrics fontMetrics()
font()
, isActive()
, and Settings.
public final boolean hasClipping()
setClipping()
, and Clipping.
public final void initFrom(QWidget widget)
begin()
while the painter is active. begin()
, and Settings.
public final boolean isActive()
begin()
has been called and end()
has not yet been called; otherwise returns false. begin()
, and QPaintDevice::paintingActive()
.
public final Qt.LayoutDirection layoutDirection()
setLayoutDirection()
, drawText()
, and Settings.
public final double opacity()
setOpacity()
.
public final QPaintEngine paintEngine()
isActive()
.
public final QPen pen()
setPen()
, and Settings.
public final QPainter.RenderHints renderHints()
setRenderHints()
, testRenderHint()
, and Rendering Quality.
public final void resetMatrix()
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.
public final void resetTransform()
translate()
, scale()
, shear()
, rotate()
, setWorldTransform()
, setViewport()
and setWindow()
.
public final void restore()
save()
.
public final void rotate(double a)
setWorldMatrix()
, and Coordinate Transformations.
public final void save()
save()
must be followed by a corresponding restore()
; the end()
function unwinds the stack. restore()
.
public final void scale(double sx, double sy)
setWorldMatrix()
, and Coordinate Transformations.
public final void setBackground(QBrush 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).
background()
, setBackgroundMode()
, and Settings.
public final void setBackgroundMode(Qt.BGMode 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()
.
backgroundMode()
, setBackground()
, and Settings.
public final void setBrush(Qt.BrushStyle style)
public final void setBrush(QBrush brush)
The painter's brush defines how shapes are filled.
brush()
, and Settings.
public final void setBrushOrigin(QPoint arg__1)
public final void setBrushOrigin(QPointF 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.
brushOrigin()
, and Settings.
public final void setBrushOrigin(int x, int y)
public final void setClipPath(QPainterPath path)
Note that the clip path is specified in logical (painter) coordinates.
clipPath()
, clipRegion()
, and Clipping.
public final void setClipPath(QPainterPath path, Qt.ClipOperation op)
Note that the clip path is specified in logical (painter) coordinates.
clipPath()
, clipRegion()
, and Clipping.
public final void setClipRect(QRect arg__1)
public final void setClipRect(QRect arg__1, Qt.ClipOperation op)
public final void setClipRect(QRectF arg__1)
Note that the clip rectangle is specified in logical (painter) coordinates.
clipRegion()
, setClipping()
, and Clipping.
public final void setClipRect(QRectF arg__1, Qt.ClipOperation op)
public final void setClipRect(int x, int y, int w, int h)
public final void setClipRect(int x, int y, int w, int h, Qt.ClipOperation op)
public final void setClipRegion(QRegion arg__1)
Note that the clip region is given in logical coordinates.
clipRegion()
, setClipRect()
, and Clipping.
public final void setClipRegion(QRegion arg__1, Qt.ClipOperation op)
Note that the clip region is given in logical coordinates.
clipRegion()
, setClipRect()
, and Clipping.
public final void setClipping(boolean enable)
hasClipping()
, and Clipping.
public final void setCompositionMode(QPainter.CompositionMode mode)
Warning: You can only set the composition mode for QPainter objects that operates on a QImage
.
compositionMode()
.
public final void setFont(QFont 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).
font()
, drawText()
, and Settings.
public final void setLayoutDirection(Qt.LayoutDirection direction)
layoutDirection()
, drawText()
, and Settings.
public final void setOpacity(double opacity)
Opacity set on the painter will apply to all drawing operations individually.
opacity()
.
public final void setPen(Qt.PenStyle style)
public final void setPen(QColor color)
Qt::SolidLine
, width 0 and the specified color.
public final void setPen(QPen pen)
The pen defines how to draw lines and outlines, and it also defines the text color.
pen()
, and Settings.
public final void setRenderHint(QPainter.RenderHint hint)
setRenderHints()
, renderHints()
, and Rendering Quality.
public final void setRenderHint(QPainter.RenderHint hint, boolean on)
setRenderHints()
, renderHints()
, and Rendering Quality.
public final void setRenderHints(QPainter.RenderHints hints)
setRenderHint()
, renderHints()
, and Rendering Quality.
public final void setRenderHints(QPainter.RenderHints hints, boolean on)
setRenderHint()
, renderHints()
, and Rendering Quality.
public final void setTransform(QTransform transform)
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()
.
transform()
.
public final void setTransform(QTransform transform, boolean combine)
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()
.
transform()
.
public final void setViewTransformEnabled(boolean enable)
viewTransformEnabled()
, and Window-Viewport Conversion.
public final void setViewport(QRect viewport)
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.
viewport()
, viewTransformEnabled()
, and Window-Viewport Conversion.
public final void setViewport(int x, int y, int w, int h)
public final void setWindow(QRect window)
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.
window()
, viewTransformEnabled()
, and Window-Viewport Conversion.
public final void setWindow(int x, int y, int w, int h)
public final void setWorldMatrix(QMatrix matrix)
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
:
worldMatrix()
and are implemented like this: void rotate(double angle) { QMatrix matrix = new QMatrix(); 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.
worldMatrixEnabled()
, and QMatrix
.
public final void setWorldMatrix(QMatrix matrix, boolean combine)
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
:
worldMatrix()
and are implemented like this: void rotate(double angle) { QMatrix matrix = new QMatrix(); 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.
worldMatrixEnabled()
, and QMatrix
.
public final void setWorldMatrixEnabled(boolean enabled)
worldMatrixEnabled()
, worldMatrix()
, and Coordinate Transformations.
public final void setWorldTransform(QTransform matrix)
worldTransform()
, transform()
, and setTransform()
.
public final void setWorldTransform(QTransform matrix, boolean combine)
worldTransform()
, transform()
, and setTransform()
.
public final void shear(double sh, double sv)
setWorldMatrix()
, and Coordinate Transformations.
public final void strokePath(QPainterPath path, QPen pen)
fillPath()
, and Drawing.
public final boolean testRenderHint(QPainter.RenderHint hint)
renderHints()
, and setRenderHint()
.
public final QTransform transform()
setTransform()
.
public final void translate(QPoint offset)
public final void translate(QPointF offset)
setWorldMatrix()
, and Coordinate Transformations.
public final void translate(double dx, double dy)
public final boolean viewTransformEnabled()
setViewTransformEnabled()
, and worldMatrix()
.
public final QRect viewport()
setViewport()
, and setViewTransformEnabled()
.
public final QRect window()
setWindow()
, and setViewTransformEnabled()
.
public final QMatrix worldMatrix()
It is advisable to use worldTransform()
because worldMatrix()
does not preserve the properties of perspective transformations.
setWorldMatrix()
, Coordinate Transformations, and The Coordinate System.
public final boolean worldMatrixEnabled()
setWorldMatrixEnabled()
, worldMatrix()
, and The Coordinate System.
public final QTransform worldTransform()
setWorldTransform()
.
public static void restoreRedirected(QPaintDeviceInterface device)
setRedirected()
. redirected()
.
public static void setRedirected(QPaintDeviceInterface device, QPaintDeviceInterface replacement)
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.
redirected()
, and restoreRedirected()
.
public static void setRedirected(QPaintDeviceInterface device, QPaintDeviceInterface replacement, QPoint offset)
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.
redirected()
, and restoreRedirected()
.
public final void setBrush(QColor color)
public final void setBrush(QGradient gradient)
public final void setBrush(QPixmap pm)
public static QPaintDeviceInterface redirected(QPaintDeviceInterface device, QPoint offset)
public boolean begin(QWidget widget)
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)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |