QPainter 类

QPainter 类在小部件和其它绘画设备上履行低级描绘。 更多...

Header: #include <QPainter>
CMake: find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承者:

QStylePainter

注意: 此类的所有函数 可重入 .

公共类型

class PixmapFragment
enum CompositionMode { CompositionMode_SourceOver, CompositionMode_DestinationOver, CompositionMode_Clear, CompositionMode_Source, CompositionMode_Destination, …, RasterOp_SourceOrNotDestination }
enum PixmapFragmentHint { OpaqueHint }
flags PixmapFragmentHints
enum RenderHint { Antialiasing, TextAntialiasing, SmoothPixmapTransform, VerticalSubpixelPositioning, LosslessImageRendering }
flags RenderHints

公共函数

QPainter (QPaintDevice * device )
QPainter ()
~QPainter ()
const QBrush & background () const
Qt::BGMode backgroundMode () const
bool begin (QPaintDevice * device )
void beginNativePainting ()
QRectF boundingRect (const QRectF & rectangle , int flags , const QString & text )
QRect boundingRect (const QRect & rectangle , int flags , const QString & text )
QRect boundingRect (int x , int y , int w , int h , int flags , const QString & text )
QRectF boundingRect (const QRectF & rectangle , const QString & text , const QTextOption & option = QTextOption())
const QBrush & brush () const
QPoint brushOrigin () const
QRectF clipBoundingRect () const
QPainterPath clipPath () const
QRegion clipRegion () const
QTransform combinedTransform () const
QPainter::CompositionMode compositionMode () const
QPaintDevice * device () const
const QTransform & deviceTransform () const
void drawArc (const QRectF & rectangle , int startAngle , int spanAngle )
void drawArc (const QRect & rectangle , int startAngle , int spanAngle )
void drawArc (int x , int y , int width , int height , int startAngle , int spanAngle )
void drawChord (const QRectF & rectangle , int startAngle , int spanAngle )
void drawChord (int x , int y , int width , int height , int startAngle , int spanAngle )
void drawChord (const QRect & rectangle , int startAngle , int spanAngle )
void drawConvexPolygon (const QPointF * points , int pointCount )
void drawConvexPolygon (const QPolygonF & polygon )
void drawConvexPolygon (const QPoint * points , int pointCount )
void drawConvexPolygon (const QPolygon & polygon )
void drawEllipse (const QRectF & rectangle )
void drawEllipse (const QRect & rectangle )
void drawEllipse (int x , int y , int width , int height )
void drawEllipse (const QPointF & center , qreal rx , qreal ry )
void drawEllipse (const QPoint & center , int rx , int ry )
void drawGlyphRun (const QPointF & position , const QGlyphRun & glyphs )
void drawImage (const QRectF & target , const QImage & image , const QRectF & source , Qt::ImageConversionFlags flags = Qt::AutoColor)
void drawImage (const QRect & target , const QImage & image , const QRect & source , Qt::ImageConversionFlags flags = Qt::AutoColor)
void drawImage (const QPointF & point , const QImage & image , const QRectF & source , Qt::ImageConversionFlags flags = Qt::AutoColor)
void drawImage (const QPoint & point , const QImage & image , const QRect & source , Qt::ImageConversionFlags flags = Qt::AutoColor)
void drawImage (const QRectF & rectangle , const QImage & image )
void drawImage (const QRect & rectangle , const QImage & image )
void drawImage (const QPointF & point , const QImage & image )
void drawImage (const QPoint & point , const QImage & image )
void drawImage (int x , int y , const QImage & image , int sx = 0, int sy = 0, int sw = -1, int sh = -1, Qt::ImageConversionFlags flags = Qt::AutoColor)
void drawLine (const QLineF & line )
void drawLine (const QLine & line )
void drawLine (int x1 , int y1 , int x2 , int y2 )
void drawLine (const QPoint & p1 , const QPoint & p2 )
void drawLine (const QPointF & p1 , const QPointF & p2 )
void drawLines (const QLineF * lines , int lineCount )
void drawLines (const QList<QLineF> & lines )
void drawLines (const QPointF * pointPairs , int lineCount )
void drawLines (const QList<QPointF> & pointPairs )
void drawLines (const QLine * lines , int lineCount )
void drawLines (const QList<QLine> & lines )
void drawLines (const QPoint * pointPairs , int lineCount )
void drawLines (const QList<QPoint> & pointPairs )
void drawPath (const QPainterPath & path )
void drawPicture (const QPointF & point , const QPicture & picture )
void drawPicture (int x , int y , const QPicture & picture )
void drawPicture (const QPoint & point , const QPicture & picture )
void drawPie (const QRectF & rectangle , int startAngle , int spanAngle )
void drawPie (int x , int y , int width , int height , int startAngle , int spanAngle )
void drawPie (const QRect & rectangle , int startAngle , int spanAngle )
void drawPixmap (const QRectF & target , const QPixmap & pixmap , const QRectF & source )
void drawPixmap (const QRect & target , const QPixmap & pixmap , const QRect & source )
void drawPixmap (int x , int y , int w , int h , const QPixmap & pixmap , int sx , int sy , int sw , int sh )
void drawPixmap (int x , int y , const QPixmap & pixmap , int sx , int sy , int sw , int sh )
void drawPixmap (const QPointF & point , const QPixmap & pixmap , const QRectF & source )
void drawPixmap (const QPoint & point , const QPixmap & pixmap , const QRect & source )
void drawPixmap (const QPointF & point , const QPixmap & pixmap )
void drawPixmap (const QPoint & point , const QPixmap & pixmap )
void drawPixmap (int x , int y , const QPixmap & pixmap )
void drawPixmap (const QRect & rectangle , const QPixmap & pixmap )
void drawPixmap (int x , int y , int width , int height , const QPixmap & pixmap )
void drawPixmapFragments (const QPainter::PixmapFragment * fragments , int fragmentCount , const QPixmap & pixmap , QPainter::PixmapFragmentHints hints = PixmapFragmentHints())
void drawPoint (const QPointF & position )
void drawPoint (const QPoint & position )
void drawPoint (int x , int y )
void drawPoints (const QPointF * points , int pointCount )
void drawPoints (const QPolygonF & points )
void drawPoints (const QPoint * points , int pointCount )
void drawPoints (const QPolygon & points )
void drawPolygon (const QPointF * points , int pointCount , Qt::FillRule fillRule = Qt::OddEvenFill)
void drawPolygon (const QPolygonF & points , Qt::FillRule fillRule = Qt::OddEvenFill)
void drawPolygon (const QPoint * points , int pointCount , Qt::FillRule fillRule = Qt::OddEvenFill)
void drawPolygon (const QPolygon & points , Qt::FillRule fillRule = Qt::OddEvenFill)
void drawPolyline (const QPointF * points , int pointCount )
void drawPolyline (const QPolygonF & points )
void drawPolyline (const QPoint * points , int pointCount )
void drawPolyline (const QPolygon & points )
void drawRect (const QRectF & rectangle )
void drawRect (int x , int y , int width , int height )
void drawRect (const QRect & rectangle )
void drawRects (const QRectF * rectangles , int rectCount )
void drawRects (const QList<QRectF> & rectangles )
void drawRects (const QRect * rectangles , int rectCount )
void drawRects (const QList<QRect> & rectangles )
void drawRoundedRect (const QRectF & rect , qreal xRadius , qreal yRadius , Qt::SizeMode mode = Qt::AbsoluteSize)
void drawRoundedRect (int x , int y , int w , int h , qreal xRadius , qreal yRadius , Qt::SizeMode mode = Qt::AbsoluteSize)
void drawRoundedRect (const QRect & rect , qreal xRadius , qreal yRadius , Qt::SizeMode mode = Qt::AbsoluteSize)
void drawStaticText (const QPointF & topLeftPosition , const QStaticText & staticText )
void drawStaticText (const QPoint & topLeftPosition , const QStaticText & staticText )
void drawStaticText (int left , int top , const QStaticText & staticText )
void drawText (const QRectF & rectangle , int flags , const QString & text , QRectF * boundingRect = nullptr)
void drawText (const QPointF & position , const QString & text )
void drawText (const QPoint & position , const QString & text )
void drawText (int x , int y , const QString & text )
void drawText (const QRect & rectangle , int flags , const QString & text , QRect * boundingRect = nullptr)
void drawText (int x , int y , int width , int height , int flags , const QString & text , QRect * boundingRect = nullptr)
void drawText (const QRectF & rectangle , const QString & text , const QTextOption & option = QTextOption())
void drawTiledPixmap (const QRectF & rectangle , const QPixmap & pixmap , const QPointF & position = QPointF())
void drawTiledPixmap (int x , int y , int width , int height , const QPixmap & pixmap , int sx = 0, int sy = 0)
void drawTiledPixmap (const QRect & rectangle , const QPixmap & pixmap , const QPoint & position = QPoint())
bool end ()
void endNativePainting ()
void eraseRect (const QRectF & rectangle )
void eraseRect (int x , int y , int width , int height )
void eraseRect (const QRect & rectangle )
void fillPath (const QPainterPath & path , const QBrush & brush )
void fillRect (const QRectF & rectangle , const QBrush & brush )
void fillRect (int x , int y , int width , int height , const QBrush & brush )
void fillRect (const QRect & rectangle , const QBrush & brush )
void fillRect (const QRectF & rectangle , const QColor & color )
void fillRect (int x , int y , int width , int height , const QColor & color )
void fillRect (const QRect & rectangle , const QColor & color )
void fillRect (int x , int y , int width , int height , Qt::GlobalColor color )
void fillRect (const QRect & rectangle , Qt::GlobalColor color )
void fillRect (const QRectF & rectangle , Qt::GlobalColor color )
void fillRect (int x , int y , int width , int height , Qt::BrushStyle style )
void fillRect (const QRect & rectangle , Qt::BrushStyle style )
void fillRect (const QRectF & rectangle , Qt::BrushStyle style )
void fillRect (int x , int y , int width , int height , QGradient::Preset preset )
void fillRect (const QRect & rectangle , QGradient::Preset preset )
void fillRect (const QRectF & rectangle , QGradient::Preset preset )
const QFont & font () const
QFontInfo fontInfo () const
QFontMetrics fontMetrics () const
bool hasClipping () const
bool isActive () const
Qt::LayoutDirection layoutDirection () const
qreal opacity () const
QPaintEngine * paintEngine () const
const QPen & pen () const
QPainter::RenderHints renderHints () const
void resetTransform ()
void restore ()
void rotate (qreal angle )
void save ()
void scale (qreal sx , qreal sy )
void setBackground (const QBrush & brush )
void setBackgroundMode (Qt::BGMode mode )
void setBrush (const QBrush & brush )
void setBrush (Qt::BrushStyle style )
void setBrushOrigin (const QPointF & position )
void setBrushOrigin (int x , int y )
void setBrushOrigin (const QPoint & position )
void setClipPath (const QPainterPath & path , Qt::ClipOperation operation = Qt::ReplaceClip)
void setClipRect (const QRectF & rectangle , Qt::ClipOperation operation = Qt::ReplaceClip)
void setClipRect (const QRect & rectangle , Qt::ClipOperation operation = Qt::ReplaceClip)
void setClipRect (int x , int y , int width , int height , Qt::ClipOperation operation = Qt::ReplaceClip)
void setClipRegion (const QRegion & region , Qt::ClipOperation operation = Qt::ReplaceClip)
void setClipping (bool enable )
void setCompositionMode (QPainter::CompositionMode mode )
void setFont (const QFont & font )
void setLayoutDirection (Qt::LayoutDirection direction )
void setOpacity (qreal opacity )
void setPen (const QPen & pen )
void setPen (const QColor & color )
void setPen (Qt::PenStyle style )
void setRenderHint (QPainter::RenderHint hint , bool on = true)
void setRenderHints (QPainter::RenderHints hints , bool on = true)
void setTransform (const QTransform & transform , bool combine = false)
void setViewTransformEnabled (bool enable )
void setViewport (const QRect & rectangle )
void setViewport (int x , int y , int width , int height )
void setWindow (const QRect & rectangle )
void setWindow (int x , int y , int width , int height )
void setWorldMatrixEnabled (bool enable )
void setWorldTransform (const QTransform & matrix , bool combine = false)
void shear (qreal sh , qreal sv )
void strokePath (const QPainterPath & path , const QPen & pen )
bool testRenderHint (QPainter::RenderHint hint ) const
const QTransform & transform () const
void translate (const QPointF & offset )
void translate (const QPoint & offset )
void translate (qreal dx , qreal dy )
bool viewTransformEnabled () const
QRect viewport () const
QRect window () const
bool worldMatrixEnabled () const
const QTransform & worldTransform () const

详细描述

QPainter 提供高度优化的特征来做大多数的 GUI 程序绘制要求。它可以绘制从简单线条到复杂形状 (像馅饼和弦) 的一切。它还可以绘制对齐文本和像素图。通常,它在自然坐标系统中绘制,但也可以在视图和世界坐标系统之间变换。QPainter 可以操作的任何对象继承 QPaintDevice 类。

常见 QPainter 用法是在小部件描绘事件内:构造和定制 (如:设置钢笔或笔刷) 描绘器。然后绘制。记得销毁 QPainter 对象在绘制后。例如:

void SimpleExampleWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setPen(Qt::blue);
    painter.setFont(QFont("Arial", 30));
    painter.drawText(rect(), Qt::AlignCenter, "Qt");
}
							

QPainter 的核心功能是绘制,但类还提供允许定制 QPainter 设置、渲染品质及其它使能够剪辑的一些功能。另外,可以通过指定描绘器的合成模式来控制如何将不同形状合并在一起。

isActive () 函数指示描绘器是否活动。激活描绘器通过 begin () 函数且构造函数接受 QPaintDevice 自变量。 end () 函数,和析构函数将其取消激活。

连同 QPaintDevice and QPaintEngine 类,QPainter 形成用于 Qt 描绘系统的基。QPainter 是用于履行绘制操作的类。 QPaintDevice 表示可以使用 QPainter 进行描绘的设备。 QPaintEngine 提供用于在不同类型设备上描绘的描绘器接口。若描绘器活动, device () 返回描绘器在其上描绘的描绘设备,和 paintEngine () 返回描绘器目前正在操作的描绘引擎。更多信息,见 描绘系统 .

有时,可能期望其它人去描绘在不寻常 QPaintDevice 。QPainter 支持静态函数 setRedirected() 来做这。

警告: 当 paintdevice 是 Widget 时,QPainter 只可用于 paintEvent() 函数内或调用 paintEvent() 的函数内。

设置

可以根据偏好定制一些设置以进行 QPainter 绘制:

注意:其中一些设置会镜像某些绘制设备设置,如 QWidget::font ()。 QPainter::begin () 函数 (或等效 QPainter 构造函数) 从描绘设备拷贝这些属性。

可以随时保存 QPainter 状态通过调用 save () 函数将所有可用设置保存在内部堆栈。 restore () 函数将它们弹回来。

绘制

QPainter 提供绘制大多数图元的函数: drawPoint (), drawPoints (), drawLine (), drawRect (), drawRoundedRect (), drawEllipse (), drawArc (), drawPie (), drawChord (), drawPolyline (), drawPolygon (), drawConvexPolygon () 及 drawCubicBezier()。2 方便函数, drawRects () 和 drawLines (),绘制给定数量的矩形或线条,按给定数组 QRects or QLines 使用当前钢笔和笔刷。

QPainter 类还提供 fillRect () 函数填充给定 QRect ,采用给定 QBrush ,和 eraseRect () 函数擦除给定矩形内区域。

所有这些函数都有整数和浮点版本。

基本绘制范例

基本绘制 范例展示如何使用 QPainter 类显示各种样式的基本图形图元。

若需要绘制复杂形状,尤其是当需要重复这样做时,考虑创建 QPainterPath 和绘制它使用 drawPath ().

描绘器路径范例

QPainterPath 类提供用于描绘操作的容器,使图形形状能够被构造和重用。

描绘器路径 范例展示如何使用描绘器路径以构建复杂渲染形状。

QPainter 还提供 fillPath () 函数填充给定 QPainterPath 采用给定 QBrush ,和 strokePath () 函数绘制给定路径的轮廓 (即:描边路径)。

另请参阅 向量变形 范例,展示如何使用高级向量技术以绘制文本使用 QPainterPath 渐变 example which shows the different types of gradients that are available in Qt, and the 路径笔画 example which shows Qt's built-in dash patterns and shows how custom patterns can be used to extend the range of available patterns.

文本绘制的完成是使用 drawText ()。当需要细粒度定位时, boundingRect () 告诉您哪里给定 drawText () 命令会绘制。

绘制像素图和图像

有能绘制像素图/图像的函数,也就是 drawPixmap (), drawImage () 和 drawTiledPixmap (). Both drawPixmap () 和 drawImage () 产生相同结果,除了 drawPixmap () 在屏幕上更快,而 drawImage () 可能更快在 QPrinter 或其它设备。

drawPicture () 函数绘制内容为整个 QPicture drawPicture () function is the only function that disregards all the painter's settings as QPicture has its own settings.

绘制高分辨率版本的像素图和图像

像素图的高分辨率版本拥有的 设备像素比率 值大于 1 (见 QImageReader , QPixmap::devicePixelRatio ()). Should it match the value of the underlying QPaintDevice , it is drawn directly onto the device with no additional transformation applied.

This is for example the case when drawing a QPixmap of 64x64 pixels size with a device pixel ratio of 2 onto a high DPI screen which also has a device pixel ratio of 2. Note that the pixmap is then effectively 32x32 pixels in user space . Code paths in Qt that calculate layout geometry based on the pixmap size will use this size. The net effect of this is that the pixmap is displayed as high DPI pixmap rather than a large pixmap.

渲染品质

To get the optimal rendering result using QPainter, you should use the platform independent QImage 作为描绘设备;即:使用 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.

同心圆范例

同心圆 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.

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.

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 仿射变换 example for a visualization of a sheared coordinate system.

另请参阅 变换 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.

仿射变换范例

仿射变换 example shows 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 worldTransform (). A matrix transforms a point in the plane to another point. For more information about the transformation matrix, see the 坐标系统 and QTransform 文档编制。

setWorldTransform () function can replace or add to the currently set worldTransform ()。 resetTransform () function resets any transformations that were made using translate (), scale (), shear (), rotate (), setWorldTransform (), setViewport () 和 setWindow () 函数。 deviceTransform () 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 combinedTransform (), a combination of viewport () 和 window () 和 worldTransform ()。 viewport () represents the physical coordinates specifying an arbitrary rectangle, the window () describes the same rectangle in logical coordinates, and the worldTransform () is identical with the transformation matrix.

另请参阅 坐标系统

剪辑

QPainter can clip any drawing operation to a rectangle, a region, or a vector path. The current clip is available using the functions clipRegion () 和 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 () 或 hasClipping ().

合成模式

QPainter 提供 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 graphic 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, effectively clearing those, while the primitive only overwrites its own area.

合成模式范例

合成模式 example, available in Qt's examples directory, allows you to experiment with the various composition modes and see the results immediately.

局限性

If you are using coordinates with Qt's raster-based paint engine, it is important to note that, while coordinates greater than +/- 2 15 can be used, any painting performed with coordinates outside this range is not guaranteed to be shown; the drawing may be clipped. This is due to the use of short int 在实现中。

The outlines generated by Qt's stroker are only an approximation when dealing with curved shapes. It is in most cases impossible to represent the outline of a bezier curve segment using another bezier curve segment, and so Qt approximates the curve outlines by using several smaller curves. For performance reasons there is a limit to how many curves Qt uses for these outlines, and thus when using large pen widths or scales the outline error increases. To generate outlines with smaller errors it is possible to use the QPainterPathStroker class, which has the setCurveThreshold member function which let's the user specify the error tolerance. Another workaround is to convert the paths to polygons first and then draw the polygons instead.

性能

QPainter is a rich framework that allows developers to do a great variety of graphical operations, such as gradients, composition modes and vector graphics. And QPainter can do this across a variety of different hardware and software stacks. Naturally the underlying combination of hardware and software has some implications for performance, and ensuring that every single operation is fast in combination with all the various combinations of composition modes, brushes, clipping, transformation, etc, is close to an impossible task because of the number of permutations. As a compromise we have selected a subset of the QPainter API and backends, where performance is guaranteed to be as good as we can sensibly get it for the given combination of hardware and software.

The backends we focus on as high-performance engines are:

  • Raster - This backend implements all rendering in pure software and is always used to render into QImages. For optimal performance only use the format types QImage::Format_ARGB32_Premultiplied , QImage::Format_RGB32 or QImage::Format_RGB16 . Any other format, including QImage::Format_ARGB32 , has significantly worse performance. This engine is used by default for QWidget and QPixmap .
  • OpenGL 2.0 (ES) - This backend is the primary backend for hardware accelerated graphics. It can be run on desktop machines and embedded devices supporting the OpenGL 2.0 or OpenGL/ES 2.0 specification. This includes most graphics chips produced in the last couple of years. The engine can be enabled by using QPainter onto a QOpenGLWidget .

These operations are:

  • Simple transformations, meaning translation and scaling, pluss 0, 90, 180, 270 degree rotations.
  • drawPixmap() in combination with simple transformations and opacity with non-smooth transformation mode ( QPainter::SmoothPixmapTransform not enabled as a render hint).
  • Rectangle fills with solid color, two-color linear gradients and simple transforms.
  • Rectangular clipping with simple transformations and intersect clip.
  • 合成模式 QPainter::CompositionMode_Source and QPainter::CompositionMode_SourceOver .
  • Rounded rectangle filling using solid color and two-color linear gradients fills.
  • 3x3 patched pixmaps, via qDrawBorderPixmap.

This list gives an indication of which features to safely use in an application where performance is critical. For certain setups, other operations may be fast too, but before making extensive use of them, it is recommended to benchmark and verify them on the system where the software will run in the end. There are also cases where expensive operations are ok to use, for instance when the result is cached in a QPixmap .

另请参阅 QPaintDevice , QPaintEngine , Qt SVG , 基本绘制范例 ,和 Drawing Utility Functions .

成员类型文档编制

enum QPainter:: CompositionMode

Defines the modes supported for digital image compositing. Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.

Please note that the bitwise raster operation modes, denoted with a RasterOp prefix, are only natively supported in the X11 and raster paint engines. This means that the only way to utilize these modes on the Mac is via a QImage . The RasterOp denoted blend modes are not supported for pens and brushes with alpha components. Also, turning on the QPainter::Antialiasing render hint will effectively disable the RasterOp modes.

The most common type is SourceOver (often referred to as just alpha blending) where the source pixel is blended on top of the destination pixel in such a way that the alpha component of the source defines the translucency of the pixel.

Several composition modes require an alpha channel in the source or target images to have an effect. For optimal performance the image format Format_ARGB32_Premultiplied is preferred.

When a composition mode is set it applies to all painting operator, pens, brushes, gradients and pixmap/image drawing.

常量 描述
QPainter::CompositionMode_SourceOver 0 This is the default mode. The alpha of the source is used to blend the pixel on top of the destination.
QPainter::CompositionMode_DestinationOver 1 The alpha of the destination is used to blend it on top of the source pixels. This mode is the inverse of CompositionMode_SourceOver.
QPainter::CompositionMode_Clear 2 The pixels in the destination are cleared (set to fully transparent) independent of the source.
QPainter::CompositionMode_Source 3 The output is the source pixel. (This means a basic copy operation and is identical to SourceOver when the source pixel is opaque).
QPainter::CompositionMode_Destination 4 The output is the destination pixel. This means that the blending has no effect. This mode is the inverse of CompositionMode_Source.
QPainter::CompositionMode_SourceIn 5 The output is the source, where the alpha is reduced by that of the destination.
QPainter::CompositionMode_DestinationIn 6 The output is the destination, where the alpha is reduced by that of the source. This mode is the inverse of CompositionMode_SourceIn.
QPainter::CompositionMode_SourceOut 7 The output is the source, where the alpha is reduced by the inverse of destination.
QPainter::CompositionMode_DestinationOut 8 The output is the destination, where the alpha is reduced by the inverse of the source. This mode is the inverse of CompositionMode_SourceOut.
QPainter::CompositionMode_SourceAtop 9 The source pixel is blended on top of the destination, with the alpha of the source pixel reduced by the alpha of the destination pixel.
QPainter::CompositionMode_DestinationAtop 10 The destination pixel is blended on top of the source, with the alpha of the destination pixel is reduced by the alpha of the destination pixel. This mode is the inverse of CompositionMode_SourceAtop.
QPainter::CompositionMode_Xor 11 The source, whose alpha is reduced with the inverse of the destination alpha, is merged with the destination, whose alpha is reduced by the inverse of the source alpha. CompositionMode_Xor is not the same as the bitwise Xor.
QPainter::CompositionMode_Plus 12 Both the alpha and color of the source and destination pixels are added together.
QPainter::CompositionMode_Multiply 13 The output is the source color multiplied by the destination. Multiplying a color with white leaves the color unchanged, while multiplying a color with black produces black.
QPainter::CompositionMode_Screen 14 The source and destination colors are inverted and then multiplied. Screening a color with white produces white, whereas screening a color with black leaves the color unchanged.
QPainter::CompositionMode_Overlay 15 Multiplies or screens the colors depending on the destination color. The destination color is mixed with the source color to reflect the lightness or darkness of the destination.
QPainter::CompositionMode_Darken 16 The darker of the source and destination colors is selected.
QPainter::CompositionMode_Lighten 17 The lighter of the source and destination colors is selected.
QPainter::CompositionMode_ColorDodge 18 The destination color is brightened to reflect the source color. A black source color leaves the destination color unchanged.
QPainter::CompositionMode_ColorBurn 19 The destination color is darkened to reflect the source color. A white source color leaves the destination color unchanged.
QPainter::CompositionMode_HardLight 20 Multiplies or screens the colors depending on the source color. A light source color will lighten the destination color, whereas a dark source color will darken the destination color.
QPainter::CompositionMode_SoftLight 21 Darkens or lightens the colors depending on the source color. Similar to CompositionMode_HardLight.
QPainter::CompositionMode_Difference 22 Subtracts the darker of the colors from the lighter. Painting with white inverts the destination color, whereas painting with black leaves the destination color unchanged.
QPainter::CompositionMode_Exclusion 23 Similar to CompositionMode_Difference, but with a lower contrast. Painting with white inverts the destination color, whereas painting with black leaves the destination color unchanged.
QPainter::RasterOp_SourceOrDestination 24 Does a bitwise OR operation on the source and destination pixels (src OR dst).
QPainter::RasterOp_SourceAndDestination 25 Does a bitwise AND operation on the source and destination pixels (src AND dst).
QPainter::RasterOp_SourceXorDestination 26 Does a bitwise XOR operation on the source and destination pixels (src XOR dst).
QPainter::RasterOp_NotSourceAndNotDestination 27 Does a bitwise NOR operation on the source and destination pixels ((NOT src) AND (NOT dst)).
QPainter::RasterOp_NotSourceOrNotDestination 28 Does a bitwise NAND operation on the source and destination pixels ((NOT src) OR (NOT dst)).
QPainter::RasterOp_NotSourceXorDestination 29 Does a bitwise operation where the source pixels are inverted and then XOR'ed with the destination ((NOT src) XOR dst).
QPainter::RasterOp_NotSource 30 Does a bitwise operation where the source pixels are inverted (NOT src).
QPainter::RasterOp_NotSourceAndDestination 31 Does a bitwise operation where the source is inverted and then AND'ed with the destination ((NOT src) AND dst).
QPainter::RasterOp_SourceAndNotDestination 32 Does a bitwise operation where the source is AND'ed with the inverted destination pixels (src AND (NOT dst)).
QPainter::RasterOp_NotSourceOrDestination 33 Does a bitwise operation where the source is inverted and then OR'ed with the destination ((NOT src) OR dst).
QPainter::RasterOp_ClearDestination 35 The pixels in the destination are cleared (set to 0) independent of the source.
QPainter::RasterOp_SetDestination 36 The pixels in the destination are set (set to 1) independent of the source.
QPainter::RasterOp_NotDestination 37 Does a bitwise operation where the destination pixels are inverted (NOT dst).
QPainter::RasterOp_SourceOrNotDestination 34 Does a bitwise operation where the source is OR'ed with the inverted destination pixels (src OR (NOT dst)).

另请参阅 compositionMode (), setCompositionMode (), 合成模式 ,和 图像合成范例 .

enum QPainter:: PixmapFragmentHint
flags QPainter:: PixmapFragmentHints

常量 描述
QPainter::OpaqueHint 0x01 Indicates that the pixmap fragments to be drawn are opaque. Opaque fragments are potentially faster to draw.

The PixmapFragmentHints type is a typedef for QFlags <PixmapFragmentHint>. It stores an OR combination of PixmapFragmentHint values.

另请参阅 QPainter::drawPixmapFragments () 和 QPainter::PixmapFragment .

enum QPainter:: RenderHint
flags QPainter:: RenderHints

Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine.

常量 描述
QPainter::Antialiasing 0x01 Indicates that the engine should antialias edges of primitives if possible.
QPainter::TextAntialiasing 0x02 Indicates that the engine should antialias text if possible. To forcibly disable antialiasing for text, do not use this hint. Instead, set QFont::NoAntialias on your font's style strategy.
QPainter::SmoothPixmapTransform 0x04 Indicates that the engine should use a smooth pixmap transformation algorithm (such as bilinear) rather than nearest neighbor.
QPainter::VerticalSubpixelPositioning 0x08 Allow text to be positioned at fractions of pixels vertically as well as horizontally, if this is supported by the font engine. This is currently supported by Freetype on all platforms when the hinting preference is QFont::PreferNoHinting , and also on macOS. For most use cases this will not improve visual quality, but may increase memory consumption and some reduction in text rendering performance. Therefore, enabling this is not recommended unless the use case requires it. One such use case could be aligning glyphs with other visual primitives. This value was added in Qt 6.1.
QPainter::LosslessImageRendering 0x40 Use a lossless image rendering, whenever possible. Currently, this hint is only used when QPainter is employed to output a PDF file through QPrinter or QPdfWriter ,其中 drawImage ()/ drawPixmap () calls will encode images using a lossless compression algorithm instead of lossy JPEG compression. This value was added in Qt 5.13.

The RenderHints type is a typedef for QFlags <RenderHint>. It stores an OR combination of RenderHint values.

另请参阅 renderHints (), setRenderHint (), 渲染品质 ,和 同心圆范例 .

成员函数文档编制

QPainter:: QPainter ( QPaintDevice * device )

Constructs a painter that begins painting the paint device 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 () 和 end ():

void MyWidget::paintEvent(QPaintEvent *)
{
    QPainter p;
    p.begin(this);
    p.drawLine(drawingCode);        // drawing code
    p.end();
}
							

The same example using this constructor:

void MyWidget::paintEvent(QPaintEvent *)
{
    QPainter p(this);
    p.drawLine(drawingCode);        // drawing code
}
							

Since the constructor cannot provide feedback when the initialization of the painter failed you should rather use begin () 和 end () to paint on external devices, e.g. printers.

另请参阅 begin () 和 end ().

QPainter:: QPainter ()

构造描绘器。

另请参阅 begin () 和 end ().

QPainter:: ~QPainter ()

销毁描绘器。

const QBrush &QPainter:: background () const

返回当前背景笔刷。

另请参阅 setBackground () 和 设置 .

Qt::BGMode QPainter:: backgroundMode () const

返回当前背景模式。

另请参阅 setBackgroundMode () 和 设置 .

bool QPainter:: begin ( QPaintDevice * device )

Begins painting the paint device 并返回 true 若成功;否则返回 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.

警告: A paint device can only be painted by one painter at a time.

警告: Painting on a QImage with the format QImage::Format_Indexed8 不被支持。

另请参阅 end () 和 QPainter ().

void QPainter:: beginNativePainting ()

Flushes the painting pipeline and prepares for the user issuing commands directly to the underlying graphics context. Must be followed by a call to endNativePainting ().

Note that only the states the underlying paint engine changes will be reset to their respective default states. The states we reset may change from release to release. The following states are currently reset in the OpenGL 2 engine:

  • blending is disabled
  • the depth, stencil and scissor tests are disabled
  • the active texture unit is reset to 0
  • the depth mask, depth function and the clear depth are reset to their default values
  • the stencil mask, stencil operation and stencil function are reset to their default values
  • the current color is reset to solid white

If, for example, the OpenGL polygon mode is changed by the user inside a beginNativePaint()/ endNativePainting () block, it will not be reset to the default state by endNativePainting (). Here is an example that shows intermixing of painter commands and raw OpenGL commands:

QPainter painter(this);
painter.fillRect(0, 0, 128, 128, Qt::green);
painter.beginNativePainting();
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, 64, 64);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
painter.endNativePainting();
							

另请参阅 endNativePainting ().

QRectF QPainter:: boundingRect (const QRectF & rectangle , int flags , const QString & text )

Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle 采用指定 flags using the currently set font (); i.e the function tells you where the drawText () function will draw when given the same arguments.

text does not fit within the given rectangle 使用指定 flags , the function returns the required rectangle.

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 ,和 Qt::TextFlag .

QRect QPainter:: boundingRect (const QRect & rectangle , int flags , const QString & text )

这是重载函数。

Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle 采用指定 flags using the currently set font ().

QRect QPainter:: boundingRect ( int x , int y , int w , int h , int flags , const QString & 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 QPainter:: boundingRect (const QRectF & rectangle , const QString & text , const QTextOption & option = QTextOption())

这是重载函数。

Instead of specifying flags as a bitwise OR of the Qt::AlignmentFlag and Qt::TextFlag , this overloaded function takes an option 自变量。 QTextOption class provides a description of general rich text properties.

另请参阅 QTextOption .

const QBrush &QPainter:: brush () const

返回描绘器的当前笔刷。

另请参阅 QPainter::setBrush () 和 设置 .

QPoint QPainter:: brushOrigin () const

返回目前设置的笔刷原点。

另请参阅 setBrushOrigin () 和 设置 .

QRectF QPainter:: clipBoundingRect () const

Returns the bounding rectangle of the current clip if there is a clip; otherwise returns an empty rectangle. Note that the clip region is given in logical coordinates.

The bounding rectangle is not guaranteed to be tight.

另请参阅 setClipRect (), setClipPath (),和 setClipRegion ().

QPainterPath QPainter:: clipPath () const

按逻辑坐标返回当前的剪辑路径。

警告: QPainter does not store the combined clip explicitly as this is handled by the underlying QPaintEngine , so the path is recreated on demand and transformed to the current logical coordinate system. This is potentially an expensive operation.

另请参阅 setClipPath (), clipRegion (),和 setClipping ().

QRegion QPainter:: clipRegion () const

Returns the currently set clip region. Note that the clip region is given in logical coordinates.

警告: QPainter does not store the combined clip explicitly as this is handled by the underlying QPaintEngine , so the path is recreated on demand and transformed to the current logical coordinate system. This is potentially an expensive operation.

另请参阅 setClipRegion (), clipPath (),和 setClipping ().

QTransform QPainter:: combinedTransform () const

Returns the transformation matrix combining the current window/viewport and world transformation.

另请参阅 setWorldTransform (), setWindow (),和 setViewport ().

QPainter::CompositionMode QPainter:: compositionMode () const

Returns the current composition mode.

另请参阅 CompositionMode and setCompositionMode ().

QPaintDevice *QPainter:: device () const

Returns the paint device on which this painter is currently painting, or nullptr if the painter is not active.

另请参阅 isActive ().

const QTransform &QPainter:: deviceTransform () const

Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.

此函数是 only needed when using platform painting commands on the platform dependent handle ( Qt::HANDLE ), and the platform does not do transformations nativly.

QPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.

另请参阅 worldTransform () 和 QPaintEngine::hasFeature ().

void QPainter:: drawArc (const QRectF & rectangle , int startAngle , int spanAngle )

Draws the arc defined by the given rectangle , startAngle and spanAngle .

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.drawArc(rectangle, startAngle, spanAngle);
										

另请参阅 drawPie (), drawChord (),和 坐标系统 .

void QPainter:: drawArc (const QRect & rectangle , int startAngle , int spanAngle )

这是重载函数。

Draws the arc defined by the given rectangle , startAngle and spanAngle .

void QPainter:: drawArc ( int x , int y , int width , int height , int startAngle , int spanAngle )

这是重载函数。

Draws the arc defined by the rectangle beginning at ( x , y ) with the specified width and height ,和给定 startAngle and spanAngle .

void QPainter:: drawChord (const QRectF & rectangle , int startAngle , int spanAngle )

Draws the chord defined by the given rectangle , startAngle and spanAngle . 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);
										

另请参阅 drawArc (), drawPie (),和 坐标系统 .

void QPainter:: drawChord ( int x , int y , int width , int height , int startAngle , int spanAngle )

这是重载函数。

Draws the chord defined by the rectangle beginning at ( x , y ) with the specified width and height ,和给定 startAngle and spanAngle .

void QPainter:: drawChord (const QRect & rectangle , int startAngle , int spanAngle )

这是重载函数。

Draws the chord defined by the given rectangle , startAngle and spanAngle .

void QPainter:: drawConvexPolygon (const QPointF * points , int pointCount )

Draws the convex polygon defined by the first pointCount points in the array points using the current pen.

static const QPointF points[4] = {
    QPointF(10.0, 80.0),
    QPointF(20.0, 10.0),
    QPointF(80.0, 30.0),
    QPointF(90.0, 70.0)
};
QPainter painter(this);
painter.drawConvexPolygon(points, 4);
										

The first point is implicitly connected to the last point, and the polygon is filled with the current brush (). If the supplied polygon is not convex, i.e. it contains at least one angle larger than 180 degrees, the results are undefined.

On some platforms (e.g. X11), the drawConvexPolygon() function can be faster than the drawPolygon () 函数。

另请参阅 drawPolygon (), drawPolyline (),和 坐标系统 .

void QPainter:: drawConvexPolygon (const QPolygonF & polygon )

这是重载函数。

Draws the convex polygon defined by polygon 使用当前钢笔和笔刷。

void QPainter:: drawConvexPolygon (const QPoint * points , int pointCount )

这是重载函数。

Draws the convex polygon defined by the first pointCount points in the array points using the current pen.

void QPainter:: drawConvexPolygon (const QPolygon & polygon )

这是重载函数。

Draws the convex polygon defined by polygon 使用当前钢笔和笔刷。

void QPainter:: drawEllipse (const QRectF & rectangle )

Draws the ellipse defined by the given rectangle .

A filled ellipse has a size of rectangle . size() . A stroked ellipse has a size of rectangle . size() plus the pen width.

QRectF rectangle(10.0, 20.0, 80.0, 60.0);
QPainter painter(this);
painter.drawEllipse(rectangle);
										

另请参阅 drawPie () 和 坐标系统 .

void QPainter:: drawEllipse (const QRect & rectangle )

这是重载函数。

Draws the ellipse defined by the given rectangle .

void QPainter:: drawEllipse ( int x , int y , int width , int height )

这是重载函数。

Draws the ellipse defined by the rectangle beginning at ( x , y ) 采用给定 width and height .

void QPainter:: drawEllipse (const QPointF & center , qreal rx , qreal ry )

这是重载函数。

Draws the ellipse positioned at center with radii rx and ry .

void QPainter:: drawEllipse (const QPoint & center , int rx , int ry )

这是重载函数。

Draws the ellipse positioned at center with radii rx and ry .

void QPainter:: drawGlyphRun (const QPointF & position , const QGlyphRun & glyphs )

Draws the glyphs represented by glyphs at position position gives the edge of the baseline for the string of glyphs. The glyphs will be retrieved from the font selected on glyphs and at offsets given by the positions in glyphs .

另请参阅 QGlyphRun::setRawFont (), QGlyphRun::setPositions (),和 QGlyphRun::setGlyphIndexes ().

void QPainter:: drawImage (const QRectF & target , const QImage & image , const QRectF & source , Qt::ImageConversionFlags flags = Qt::AutoColor)

Draws the rectangular portion source 为给定 image into the target rectangle in the paint device.

注意: The image is scaled to fit the rectangle, if both the image and rectangle size disagree.

注意: 绘制高分辨率版本的像素图和图像 on how this is affected by QImage::devicePixelRatio ().

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 painter(this);
painter.drawImage(target, image, source);
										

另请参阅 drawPixmap () 和 QImage::devicePixelRatio ().

void QPainter:: drawImage (const QRect & target , const QImage & image , const QRect & source , Qt::ImageConversionFlags flags = Qt::AutoColor)

这是重载函数。

Draws the rectangular portion source 为给定 image into the target rectangle in the paint device.

注意: The image is scaled to fit the rectangle, if both the image and rectangle size disagree.

void QPainter:: drawImage (const QPointF & point , const QImage & image , const QRectF & source , Qt::ImageConversionFlags flags = Qt::AutoColor)

这是重载函数。

Draws the rectangular portion source 为给定 image 采用其原点在给定 point .

void QPainter:: drawImage (const QPoint & point , const QImage & image , const QRect & source , Qt::ImageConversionFlags flags = Qt::AutoColor)

这是重载函数。

Draws the rectangular portion source 为给定 image 采用其原点在给定 point .

void QPainter:: drawImage (const QRectF & rectangle , const QImage & image )

这是重载函数。

绘制给定 image 进给定 rectangle .

注意: The image is scaled to fit the rectangle, if both the image and rectangle size disagree.

void QPainter:: drawImage (const QRect & rectangle , const QImage & image )

这是重载函数。

绘制给定 image 进给定 rectangle .

注意: The image is scaled to fit the rectangle, if both the image and rectangle size disagree.

void QPainter:: drawImage (const QPointF & point , const QImage & image )

这是重载函数。

绘制给定 image 在给定 point .

void QPainter:: drawImage (const QPoint & point , const QImage & image )

这是重载函数。

绘制给定 image 在给定 point .

void QPainter:: drawImage ( int x , int y , const QImage & image , int sx = 0, int sy = 0, int sw = -1, int sh = -1, Qt::ImageConversionFlags flags = Qt::AutoColor)

这是重载函数。

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.

void QPainter:: drawLine (const QLineF & line )

Draws a line defined by line .

QLineF line(10.0, 80.0, 90.0, 20.0);
QPainter(this);
painter.drawLine(line);
										

另请参阅 drawLines (), drawPolyline (),和 坐标系统 .

void QPainter:: drawLine (const QLine & line )

这是重载函数。

Draws a line defined by line .

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

这是重载函数。

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

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

这是重载函数。

Draws a line from p1 to p2 .

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

这是重载函数。

Draws a line from p1 to p2 .

void QPainter:: drawLines (const QLineF * lines , int lineCount )

Draws the first lineCount lines in the array lines using the current pen.

另请参阅 drawLine () 和 drawPolyline ().

void QPainter:: drawLines (const QList < QLineF > & lines )

这是重载函数。

Draws the set of lines defined by the list lines 使用当前钢笔和笔刷。

void QPainter:: drawLines (const QPointF * pointPairs , int lineCount )

这是重载函数。

Draws the first lineCount lines in the array pointPairs using the current pen. The lines are specified as pairs of points so the number of entries in pointPairs must be at least lineCount * 2.

void QPainter:: drawLines (const QList < 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.

void QPainter:: drawLines (const QLine * lines , int lineCount )

这是重载函数。

Draws the first lineCount lines in the array lines using the current pen.

void QPainter:: drawLines (const QList < QLine > & lines )

这是重载函数。

Draws the set of lines defined by the list lines 使用当前钢笔和笔刷。

void QPainter:: drawLines (const QPoint * pointPairs , int lineCount )

这是重载函数。

Draws the first lineCount lines in the array pointPairs using the current pen.

void QPainter:: drawLines (const QList < QPoint > & pointPairs )

这是重载函数。

Draws a line for each pair of points in the vector pointPairs using the current pen.

void QPainter:: drawPath (const QPainterPath & path )

绘制给定描绘器 path 使用当前钢笔为轮廓和使用当前笔刷为填充。

QPainterPath path;
path.moveTo(20, 80);
path.lineTo(20, 30);
path.cubicTo(80, 0, 50, 50, 80, 80);
QPainter painter(this);
painter.drawPath(path);
										

另请参阅 the Painter Paths example and the Vector Deformation example .

void QPainter:: drawPicture (const QPointF & point , const QPicture & picture )

重演给定 picture 在给定 point .

QPicture 类是描绘设备,它记录并重演 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 point = QPointF (0, 0).

注意: The state of the painter is preserved by this function.

QPicture picture;
QPointF point(10.0, 20.0);
picture.load("drawing.pic");
QPainter painter(this);
painter.drawPicture(0, 0, picture);
										

另请参阅 QPicture::play ().

void QPainter:: drawPicture ( int x , int y , const QPicture & picture )

这是重载函数。

绘制给定 picture 在点 ( x , y ).

void QPainter:: drawPicture (const QPoint & point , const QPicture & picture )

这是重载函数。

重演给定 picture 在给定 point .

void QPainter:: drawPie (const QRectF & rectangle , int startAngle , int spanAngle )

Draws a pie defined by the given rectangle , startAngle and spanAngle .

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

另请参阅 drawEllipse (), drawChord (),和 坐标系统 .

void QPainter:: drawPie ( int x , int y , int width , int height , int startAngle , int spanAngle )

这是重载函数。

Draws the pie defined by the rectangle beginning at ( x , y ) with the specified width and height ,和给定 startAngle and spanAngle .

void QPainter:: drawPie (const QRect & rectangle , int startAngle , int spanAngle )

这是重载函数。

Draws a pie defined by the given rectangle , startAngle and and spanAngle .

void QPainter:: drawPixmap (const QRectF & target , const QPixmap & pixmap , const QRectF & source )

Draws the rectangular portion source 为给定 pixmap 进给定 target in the paint device.

注意: The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.

注意: 绘制高分辨率版本的像素图和图像 on how this is affected by QPixmap::devicePixelRatio ().

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, pixmap, source);
										

pixmap 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 () 和 QPixmap::devicePixelRatio ().

void QPainter:: drawPixmap (const QRect & target , const QPixmap & pixmap , const QRect & source )

这是重载函数。

Draws the rectangular portion source 为给定 pixmap 进给定 target in the paint device.

注意: The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.

void QPainter:: drawPixmap ( int x , int y , int w , int h , const QPixmap & pixmap , 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 . If sw or sh are equal to zero the width/height of the pixmap is used and adjusted by the offset sx/sy;

void QPainter:: drawPixmap ( int x , int y , const QPixmap & pixmap , 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.

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

void QPainter:: drawPixmap (const QPointF & point , const QPixmap & pixmap , const QRectF & source )

这是重载函数。

Draws the rectangular portion source 为给定 pixmap 采用其原点在给定 point .

void QPainter:: drawPixmap (const QPoint & point , const QPixmap & pixmap , const QRect & source )

这是重载函数。

Draws the rectangular portion source 为给定 pixmap 采用其原点在给定 point .

void QPainter:: drawPixmap (const QPointF & point , const QPixmap & pixmap )

这是重载函数。

绘制给定 pixmap 采用其原点在给定 point .

void QPainter:: drawPixmap (const QPoint & point , const QPixmap & pixmap )

这是重载函数。

绘制给定 pixmap 采用其原点在给定 point .

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

这是重载函数。

绘制给定 pixmap at position ( x , y ).

void QPainter:: drawPixmap (const QRect & rectangle , const QPixmap & pixmap )

这是重载函数。

绘制给定 pixmap 进给定 rectangle .

注意: The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.

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

这是重载函数。

Draws the pixmap into the rectangle at position ( x , y ) 采用给定 width and height .

void QPainter:: drawPixmapFragments (const QPainter::PixmapFragment * fragments , int fragmentCount , const QPixmap & pixmap , QPainter::PixmapFragmentHints hints = PixmapFragmentHints())

This function is used to draw pixmap , or a sub-rectangle of pixmap , at multiple positions with different scale, rotation and opacity. fragments is an array of fragmentCount elements specifying the parameters used to draw each pixmap fragment. The hints parameter can be used to pass in drawing hints.

This function is potentially faster than multiple calls to drawPixmap (), since the backend can optimize state changes.

另请参阅 QPainter::PixmapFragment and QPainter::PixmapFragmentHint .

void QPainter:: drawPoint (const QPointF & position )

Draws a single point at the given position using the current pen's color.

另请参阅 坐标系统 .

void QPainter:: drawPoint (const QPoint & position )

这是重载函数。

Draws a single point at the given position using the current pen's color.

void QPainter:: drawPoint ( int x , int y )

这是重载函数。

Draws a single point at position ( x , y ).

void QPainter:: drawPoints (const QPointF * points , int pointCount )

Draws the first pointCount points in the array points using the current pen's color.

另请参阅 坐标系统 .

void QPainter:: drawPoints (const QPolygonF & points )

这是重载函数。

Draws the points in the vector points .

void QPainter:: drawPoints (const QPoint * points , int pointCount )

这是重载函数。

Draws the first pointCount points in the array points using the current pen's color.

void QPainter:: drawPoints (const QPolygon & points )

这是重载函数。

Draws the points in the vector points .

void QPainter:: drawPolygon (const QPointF * points , int pointCount , Qt::FillRule fillRule = Qt::OddEvenFill)

Draws the polygon defined by the first pointCount points in the array points 使用当前钢笔和笔刷。

static const QPointF points[4] = {
    QPointF(10.0, 80.0),
    QPointF(20.0, 10.0),
    QPointF(80.0, 30.0),
    QPointF(90.0, 70.0)
};
QPainter painter(this);
painter.drawPolygon(points, 4);
										

The first point is implicitly connected to the last point, and the polygon is filled with the current brush ().

fillRule is Qt::WindingFill , the polygon is filled using the winding fill algorithm. If fillRule is Qt::OddEvenFill , the polygon is filled using the odd-even fill algorithm. See Qt::FillRule for a more detailed description of these fill rules.

另请参阅 drawConvexPolygon (), drawPolyline (),和 坐标系统 .

void QPainter:: drawPolygon (const QPolygonF & points , Qt::FillRule fillRule = Qt::OddEvenFill)

这是重载函数。

Draws the polygon defined by the given points using the fill rule fillRule .

void QPainter:: drawPolygon (const QPoint * points , int pointCount , Qt::FillRule fillRule = Qt::OddEvenFill)

这是重载函数。

Draws the polygon defined by the first pointCount points in the array points .

void QPainter:: drawPolygon (const QPolygon & points , Qt::FillRule fillRule = Qt::OddEvenFill)

这是重载函数。

Draws the polygon defined by the given points using the fill rule fillRule .

void QPainter:: drawPolyline (const QPointF * points , int pointCount )

Draws the polyline defined by the first pointCount points in points using the current pen.

Note that unlike the drawPolygon () function the last point is not connected to the first, neither is the polyline filled.

static const QPointF points[3] = {
    QPointF(10.0, 80.0),
    QPointF(20.0, 10.0),
    QPointF(80.0, 30.0),
};
QPainter painter(this);
painter.drawPolyline(points, 3);
										

另请参阅 drawLines (), drawPolygon (),和 坐标系统 .

void QPainter:: drawPolyline (const QPolygonF & points )

这是重载函数。

Draws the polyline defined by the given points using the current pen.

void QPainter:: drawPolyline (const QPoint * points , int pointCount )

这是重载函数。

Draws the polyline defined by the first pointCount points in points using the current pen.

void QPainter:: drawPolyline (const QPolygon & points )

这是重载函数。

Draws the polyline defined by the given points using the current pen.

void QPainter:: drawRect (const QRectF & rectangle )

Draws the current rectangle with the current pen and brush.

A filled rectangle has a size of rectangle .size(). A stroked rectangle has a size of rectangle .size() plus the pen width.

QRectF rectangle(10.0, 20.0, 80.0, 60.0);
QPainter painter(this);
painter.drawRect(rectangle);
										

另请参阅 drawRects (), drawPolygon (),和 坐标系统 .

void QPainter:: drawRect ( int x , int y , int width , int height )

这是重载函数。

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

void QPainter:: drawRect (const QRect & rectangle )

这是重载函数。

Draws the current rectangle with the current pen and brush.

void QPainter:: drawRects (const QRectF * rectangles , int rectCount )

Draws the first rectCount 为给定 rectangles 使用当前钢笔和笔刷。

另请参阅 drawRect ().

void QPainter:: drawRects (const QList < QRectF > & rectangles )

这是重载函数。

绘制给定 rectangles 使用当前钢笔和笔刷。

void QPainter:: drawRects (const QRect * rectangles , int rectCount )

这是重载函数。

Draws the first rectCount 为给定 rectangles 使用当前钢笔和笔刷。

void QPainter:: drawRects (const QList < QRect > & rectangles )

这是重载函数。

绘制给定 rectangles 使用当前钢笔和笔刷。

void QPainter:: drawRoundedRect (const QRectF & rect , qreal xRadius , qreal yRadius , Qt::SizeMode mode = Qt::AbsoluteSize)

Draws the given rectangle rect with rounded corners.

xRadius and yRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. When mode is Qt::RelativeSize , xRadius and yRadius are specified in percentage of half the rectangle's width and height respectively, and should be in the range 0.0 to 100.0.

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.drawRoundedRect(rectangle, 20.0, 15.0);
										

另请参阅 drawRect () 和 QPen .

void QPainter:: drawRoundedRect ( int x , int y , int w , int h , qreal xRadius , qreal yRadius , Qt::SizeMode mode = Qt::AbsoluteSize)

这是重载函数。

Draws the given rectangle x , y , w , h with rounded corners.

void QPainter:: drawRoundedRect (const QRect & rect , qreal xRadius , qreal yRadius , Qt::SizeMode mode = Qt::AbsoluteSize)

这是重载函数。

Draws the given rectangle rect with rounded corners.

void QPainter:: drawStaticText (const QPointF & topLeftPosition , const QStaticText & staticText )

绘制给定 staticText 在给定 topLeftPosition .

The text will be drawn using the font and the transformation set on the painter. If the font and/or transformation set on the painter are different from the ones used to initialize the layout of the QStaticText , then the layout will have to be recalculated. Use QStaticText::prepare () to initialize staticText with the font and transformation with which it will later be drawn.

topLeftPosition is not the same as when staticText was initialized, or when it was last drawn, then there will be a slight overhead when translating the text to its new position.

注意: If the painter's transformation is not affine, then staticText will be drawn using regular calls to drawText (), losing any potential for performance improvement.

注意: The y-position is used as the top of the font.

另请参阅 QStaticText .

void QPainter:: drawStaticText (const QPoint & topLeftPosition , const QStaticText & staticText )

这是重载函数。

Draws the staticText topLeftPosition .

注意: The y-position is used as the top of the font.

void QPainter:: drawStaticText ( int left , int top , const QStaticText & staticText )

这是重载函数。

Draws the staticText at coordinates left and top .

注意: The y-position is used as the top of the font.

void QPainter:: drawText (const QRectF & rectangle , int flags , const QString & text , QRectF * boundingRect = nullptr)

这是重载函数。

绘制给定 text within the provided rectangle rectangle along with alignment flags defines the anchors for the text .

QPainter painter(this);
painter.drawText(rect, Qt::AlignCenter, tr("Qt\nProject"));
										

boundingRect (if not null) is set to what the bounding rectangle should be in order to enclose the whole text. For example, in the following image, the dotted line represents boundingRect as calculated by the function, and the dashed line represents rectangle :

QPainter painter(this);
QFont font = painter.font();
font.setPixelSize(48);
painter.setFont(font);
const QRect rectangle = QRect(0, 0, 100, 50);
QRect boundingRect;
painter.drawText(rectangle, 0, tr("Hello"), &boundingRect);
QPen pen = painter.pen();
pen.setStyle(Qt::DotLine);
painter.setPen(pen);
painter.drawRect(boundingRect.adjusted(0, 0, -pen.width(), -pen.width()));
pen.setStyle(Qt::DashLine);
painter.setPen(pen);
painter.drawRect(rectangle.adjusted(0, 0, -pen.width(), -pen.width()));
										

flags argument is a bitwise OR of the following flags:

默认情况下, QPainter 绘制抗锯齿文本。

注意: The y-coordinate of rectangle is used as the top of the font.

另请参阅 Qt::AlignmentFlag , Qt::TextFlag , boundingRect (),和 layoutDirection ().

void QPainter:: drawText (const QPointF & position , const QString & text )

绘制给定 text with the currently defined text direction, beginning at the given position .

This function does not handle the newline character (\n), as it cannot break text into multiple lines, and it cannot display the newline character. Use the QPainter::drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.

默认情况下, QPainter 绘制抗锯齿文本。

注意: The y-position is used as the baseline of the font.

另请参阅 setFont () 和 setPen ().

void QPainter:: drawText (const QPoint & position , const QString & text )

这是重载函数。

绘制给定 text with the currently defined text direction, beginning at the given position .

默认情况下, QPainter 绘制抗锯齿文本。

注意: The y-position is used as the baseline of the font.

另请参阅 setFont () 和 setPen ().

void QPainter:: drawText ( int x , int y , const QString & text )

这是重载函数。

绘制给定 text at position ( x , y ), using the painter's currently defined text direction.

默认情况下, QPainter 绘制抗锯齿文本。

注意: The y-position is used as the baseline of the font.

另请参阅 setFont () 和 setPen ().

void QPainter:: drawText (const QRect & rectangle , int flags , const QString & text , QRect * boundingRect = nullptr)

这是重载函数。

绘制给定 text within the provided rectangle 根据指定 flags .

boundingRect (if not null) is set to the what the bounding rectangle should be in order to enclose the whole text. For example, in the following image, the dotted line represents boundingRect as calculated by the function, and the dashed line represents rectangle :

QPainter painter(this);
QFont font = painter.font();
font.setPixelSize(48);
painter.setFont(font);
const QRect rectangle = QRect(0, 0, 100, 50);
QRect boundingRect;
painter.drawText(rectangle, 0, tr("Hello"), &boundingRect);
QPen pen = painter.pen();
pen.setStyle(Qt::DotLine);
painter.setPen(pen);
painter.drawRect(boundingRect.adjusted(0, 0, -pen.width(), -pen.width()));
pen.setStyle(Qt::DashLine);
painter.setPen(pen);
painter.drawRect(rectangle.adjusted(0, 0, -pen.width(), -pen.width()));
										

默认情况下, QPainter 绘制抗锯齿文本。

注意: The y-coordinate of rectangle is used as the top of the font.

另请参阅 setFont () 和 setPen ().

void QPainter:: drawText ( int x , int y , int width , int height , int flags , const QString & text , QRect * boundingRect = nullptr)

这是重载函数。

绘制给定 text within the rectangle with origin ( x , y ), width and height .

boundingRect (if not null) is set to the what the bounding rectangle should be in order to enclose the whole text. For example, in the following image, the dotted line represents boundingRect as calculated by the function, and the dashed line represents the rectangle defined by x , y , width and height :

QPainter painter(this);
QFont font = painter.font();
font.setPixelSize(48);
painter.setFont(font);
const QRect rectangle = QRect(0, 0, 100, 50);
QRect boundingRect;
painter.drawText(rectangle, 0, tr("Hello"), &boundingRect);
QPen pen = painter.pen();
pen.setStyle(Qt::DotLine);
painter.setPen(pen);
painter.drawRect(boundingRect.adjusted(0, 0, -pen.width(), -pen.width()));
pen.setStyle(Qt::DashLine);
painter.setPen(pen);
painter.drawRect(rectangle.adjusted(0, 0, -pen.width(), -pen.width()));
										

flags argument is a bitwise OR of the following flags:

默认情况下, QPainter 绘制抗锯齿文本。

注意: The y-position is used as the top of the font.

另请参阅 Qt::AlignmentFlag , Qt::TextFlag , setFont (),和 setPen ().

void QPainter:: drawText (const QRectF & rectangle , const QString & text , const QTextOption & option = QTextOption())

这是重载函数。

绘制给定 text rectangle specified using the option to control its positioning, direction, and orientation. The options given in option override those set on the QPainter object itself.

默认情况下, QPainter 绘制抗锯齿文本。

注意: The y-coordinate of rectangle is used as the top of the font.

另请参阅 setFont () 和 setPen ().

void QPainter:: drawTiledPixmap (const QRectF & rectangle , const QPixmap & pixmap , const QPointF & position = QPointF())

绘制平铺 pixmap ,在给定 rectangle 采用其原点在给定 position .

调用 drawTiledPixmap() 类似调用 drawPixmap () several times to fill (tile) an area with a pixmap, but is potentially much more efficient depending on the underlying window system.

drawTiledPixmap() will produce the same visual tiling pattern on high-dpi displays (with devicePixelRatio > 1), compared to normal- dpi displays. Set the devicePixelRatio on the pixmap to control the tile size. For example, setting it to 2 halves the tile width and height (on both 1x and 2x displays), and produces high-resolution output on 2x displays.

position offset is always in the painter coordinate system, indepentent of display devicePixelRatio.

另请参阅 drawPixmap ().

void QPainter:: drawTiledPixmap ( int x , int y , int width , int height , const QPixmap & pixmap , int sx = 0, int sy = 0)

这是重载函数。

绘制平铺 pixmap 在指定矩形中。

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

void QPainter:: drawTiledPixmap (const QRect & rectangle , const QPixmap & pixmap , const QPoint & position = QPoint())

这是重载函数。

绘制平铺 pixmap ,在给定 rectangle 采用其原点在给定 position .

bool QPainter:: 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.

返回 true if the painter is no longer active; otherwise returns false .

另请参阅 begin () 和 isActive ().

void QPainter:: endNativePainting ()

Restores the painter after manually issuing native painting commands. Lets the painter restore any native state that it relies on before calling any other painter commands.

另请参阅 beginNativePainting ().

void QPainter:: eraseRect (const QRectF & rectangle )

擦除区域在给定 rectangle 。相当于调用

fillRect(rectangle, background());
							

另请参阅 fillRect ().

void QPainter:: eraseRect ( int x , int y , int width , int height )

这是重载函数。

擦除矩形内区域开始于 ( x , y ) 采用给定 width and height .

void QPainter:: eraseRect (const QRect & rectangle )

这是重载函数。

擦除区域在给定 rectangle .

void QPainter:: fillPath (const QPainterPath & path , const QBrush & brush )

填充给定 path 使用给定 brush 。轮廓不绘制。

另外,可以指定 QColor 而不是 QBrush QBrush 构造函数 (接受 QColor 自变量) 将自动创建纯色图案笔刷。

另请参阅 drawPath ().

void QPainter:: fillRect (const QRectF & rectangle , const QBrush & brush )

填充给定 rectangle 采用 brush 指定。

另外,可以指定 QColor 而不是 QBrush QBrush 构造函数 (接受 QColor 自变量) 将自动创建纯色图案笔刷。

另请参阅 drawRect ().

void QPainter:: fillRect ( int x , int y , int width , int height , const QBrush & brush )

这是重载函数。

填充矩形开始于 ( x , y ) 采用给定 width and height ,使用给定 brush .

void QPainter:: fillRect (const QRect & rectangle , const QBrush & brush )

这是重载函数。

填充给定 rectangle 采用指定 brush .

void QPainter:: fillRect (const QRectF & rectangle , const QColor & color )

这是重载函数。

填充给定 rectangle 采用 color 指定。

void QPainter:: fillRect ( int x , int y , int width , int height , const QColor & color )

这是重载函数。

填充矩形开始于 ( x , y ) 采用给定 width and height ,使用给定 color .

void QPainter:: fillRect (const QRect & rectangle , const QColor & color )

这是重载函数。

填充给定 rectangle 采用 color 指定。

void QPainter:: fillRect ( int x , int y , int width , int height , Qt::GlobalColor color )

这是重载函数。

填充矩形开始于 ( x , y ) 采用给定 width and height ,使用给定 color .

void QPainter:: fillRect (const QRect & rectangle , Qt::GlobalColor color )

这是重载函数。

填充给定 rectangle 采用指定 color .

void QPainter:: fillRect (const QRectF & rectangle , Qt::GlobalColor color )

这是重载函数。

填充给定 rectangle 采用指定 color .

void QPainter:: fillRect ( int x , int y , int width , int height , Qt::BrushStyle style )

这是重载函数。

填充矩形开始于 ( x , y ) 采用给定 width and height ,使用笔刷 style 指定。

void QPainter:: fillRect (const QRect & rectangle , Qt::BrushStyle style )

这是重载函数。

填充给定 rectangle with the brush style 指定。

void QPainter:: fillRect (const QRectF & rectangle , Qt::BrushStyle style )

这是重载函数。

填充给定 rectangle with the brush style 指定。

[since 5.12] void QPainter:: fillRect ( int x , int y , int width , int height , QGradient::Preset preset )

这是重载函数。

填充矩形开始于 ( x , y ) 采用给定 width and height , using the given gradient preset .

该函数在 Qt 5.12 引入。

[since 5.12] void QPainter:: fillRect (const QRect & rectangle , QGradient::Preset preset )

这是重载函数。

填充给定 rectangle with the specified gradient preset .

该函数在 Qt 5.12 引入。

[since 5.12] void QPainter:: fillRect (const QRectF & rectangle , QGradient::Preset preset )

这是重载函数。

填充给定 rectangle with the specified gradient preset .

该函数在 Qt 5.12 引入。

const QFont &QPainter:: font () const

Returns the currently set font used for drawing text.

另请参阅 setFont (), drawText (),和 设置 .

QFontInfo QPainter:: fontInfo () const

Returns the font info for the painter if the painter is active. Otherwise, the return value is undefined.

另请参阅 font (), isActive (),和 设置 .

QFontMetrics QPainter:: fontMetrics () const

Returns the font metrics for the painter if the painter is active. Otherwise, the return value is undefined.

另请参阅 font (), isActive (),和 设置 .

bool QPainter:: hasClipping () const

返回 true if clipping has been set; otherwise returns false .

另请参阅 setClipping () 和 剪辑 .

bool QPainter:: isActive () const

返回 true if begin () has been called and end () has not yet been called; otherwise returns false .

另请参阅 begin () 和 QPaintDevice::paintingActive ().

Qt::LayoutDirection QPainter:: layoutDirection () const

Returns the layout direction used by the painter when drawing text.

另请参阅 QTextOption::textDirection (), setLayoutDirection (), drawText (),和 设置 .

qreal QPainter:: opacity () const

返回描绘器的不透明度。默认值为 1。

另请参阅 setOpacity ().

QPaintEngine *QPainter:: paintEngine () const

Returns the paint engine that the painter is currently operating on if the painter is active; otherwise 0.

另请参阅 isActive ().

const QPen &QPainter:: pen () const

返回描绘器的当前钢笔。

另请参阅 setPen () 和 设置 .

QPainter::RenderHints QPainter:: renderHints () const

Returns a flag that specifies the rendering hints that are set for this painter.

另请参阅 setRenderHints (), testRenderHint (),和 渲染品质 .

void QPainter:: resetTransform ()

Resets any transformations that were made using translate (), scale (), shear (), rotate (), setWorldTransform (), setViewport () 和 setWindow ().

另请参阅 坐标变换 .

void QPainter:: restore ()

Restores the current painter state (pops a saved state off the stack).

另请参阅 save ().

void QPainter:: rotate ( qreal angle )

Rotates the coordinate system clockwise. The given angle parameter is in degrees.

另请参阅 setWorldTransform () 和 坐标变换 .

void QPainter:: 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.

另请参阅 restore ().

void QPainter:: scale ( qreal sx , qreal sy )

Scales the coordinate system by ( sx , sy ).

另请参阅 setWorldTransform () 和 坐标变换 .

void QPainter:: setBackground (const QBrush & brush )

将描绘器背景笔刷设为给定 brush .

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 (),和 设置 .

void QPainter:: setBackgroundMode ( Qt::BGMode mode )

将描绘器背景模式设为给定 mode

Qt::TransparentMode (默认) 绘制点画线和文本无需设置背景像素。 Qt::OpaqueMode 填充这些空间采用当前背景色。

注意:为绘制透明位图或像素图,必须使用 QPixmap::setMask ().

另请参阅 backgroundMode (), setBackground (),和 设置 .

void QPainter:: setBrush (const QBrush & brush )

把描绘器的笔刷设为给定 brush .

描绘器的笔刷定义形状如何被填充。

另请参阅 brush () 和 设置 .

void QPainter:: setBrush ( Qt::BrushStyle style )

这是重载函数。

把描绘器的笔刷设为黑色,并指定 style .

void QPainter:: setBrushOrigin (const QPointF & position )

Sets the brush origin to position .

The brush origin specifies the (0, 0) coordinate of the painter's brush.

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 特性到 true。

另请参阅 brushOrigin () 和 设置 .

void QPainter:: setBrushOrigin ( int x , int y )

这是重载函数。

Sets the brush's origin to point ( x , y ).

void QPainter:: setBrushOrigin (const QPoint & position )

这是重载函数。

Sets the brush's origin to the given position .

void QPainter:: setClipPath (const QPainterPath & path , Qt::ClipOperation operation = Qt::ReplaceClip)

Enables clipping, and sets the clip path for the painter to the given path , with the clip operation .

Note that the clip path is specified in logical (painter) coordinates.

另请参阅 clipPath (), clipRegion (),和 剪辑 .

void QPainter:: setClipRect (const QRectF & rectangle , Qt::ClipOperation operation = Qt::ReplaceClip)

Enables clipping, and sets the clip region to the given rectangle using the given clip operation . The default operation is to replace the current clip rectangle.

Note that the clip rectangle is specified in logical (painter) coordinates.

另请参阅 clipRegion (), setClipping (),和 剪辑 .

void QPainter:: setClipRect (const QRect & rectangle , Qt::ClipOperation operation = Qt::ReplaceClip)

这是重载函数。

Enables clipping, and sets the clip region to the given rectangle using the given clip operation .

void QPainter:: setClipRect ( int x , int y , int width , int height , Qt::ClipOperation operation = Qt::ReplaceClip)

Enables clipping, and sets the clip region to the rectangle beginning at ( x , y ) 采用给定 width and height .

void QPainter:: setClipRegion (const QRegion & region , Qt::ClipOperation operation = Qt::ReplaceClip)

Sets the clip region to the given region using the specified clip operation . The default clip operation is to replace the current clip region.

Note that the clip region is given in logical coordinates.

另请参阅 clipRegion (), setClipRect (),和 剪辑 .

void QPainter:: setClipping ( bool enable )

Enables clipping if enable is true, or disables clipping if enable is false.

另请参阅 hasClipping () 和 剪辑 .

void QPainter:: setCompositionMode ( QPainter::CompositionMode mode )

将合成模式设为给定 mode .

警告: Only a QPainter operating on a QImage fully supports all composition modes. The RasterOp modes are supported for X11 as described in compositionMode ().

另请参阅 compositionMode ().

void QPainter:: setFont (const QFont & font )

Sets the painter's font to the given font .

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 (),和 设置 .

void QPainter:: setLayoutDirection ( Qt::LayoutDirection direction )

Sets the layout direction used by the painter when drawing text, to the specified direction .

默认为 Qt::LayoutDirectionAuto , which will implicitly determine the direction from the text drawn.

另请参阅 QTextOption::setTextDirection (), layoutDirection (), drawText (),和 设置 .

void QPainter:: setOpacity ( qreal opacity )

把描绘器的不透明度设为 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.

另请参阅 opacity ().

void QPainter:: setPen (const QPen & pen )

把描绘器的钢笔,设为给定 pen .

pen 定义如何绘制线条和轮廓,且它还定义文本颜色。

另请参阅 pen () 和 设置 .

void QPainter:: setPen (const QColor & color )

这是重载函数。

Sets the painter's pen to have style Qt::SolidLine , width 1 and the specified color .

void QPainter:: setPen ( Qt::PenStyle style )

这是重载函数。

Sets the painter's pen to have the given style , width 1 and black color.

void QPainter:: setRenderHint ( QPainter::RenderHint hint , bool on = true)

Sets the given render hint on the painter if on is true; otherwise clears the render hint.

另请参阅 setRenderHints (), renderHints (),和 渲染品质 .

void QPainter:: setRenderHints ( QPainter::RenderHints hints , bool on = true)

Sets the given render hints on the painter if on is true; otherwise clears the render hints.

另请参阅 setRenderHint (), renderHints (),和 渲染品质 .

void QPainter:: setTransform (const QTransform & transform , bool combine = false)

Sets the world transformation matrix. If combine is true, the specified transform is combined with the current matrix; otherwise it replaces the current matrix.

另请参阅 transform () 和 setWorldTransform ().

void QPainter:: setViewTransformEnabled ( bool enable )

Enables view transformations if enable is true, or disables view transformations if enable is false.

另请参阅 viewTransformEnabled () 和 窗口/视口转换 .

void QPainter:: setViewport (const QRect & rectangle )

Sets the painter's viewport rectangle to the given rectangle , 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.

另请参阅 viewport (), viewTransformEnabled (),和 窗口/视口转换 .

void QPainter:: setViewport ( int x , int y , int width , int height )

这是重载函数。

Sets the painter's viewport rectangle to be the rectangle beginning at ( x , y ) 采用给定 width and height .

void QPainter:: setWindow (const QRect & rectangle )

Sets the painter's window to the given rectangle , 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.

另请参阅 window (), viewTransformEnabled (),和 窗口/视口转换 .

void QPainter:: setWindow ( int x , int y , int width , int height )

这是重载函数。

Sets the painter's window to the rectangle beginning at ( x , y ) and the given width and height .

void QPainter:: setWorldMatrixEnabled ( bool enable )

Enables transformations if enable is true, or disables transformations if enable is false. The world transformation matrix is not changed.

另请参阅 worldMatrixEnabled (), worldTransform (),和 坐标变换 .

void QPainter:: setWorldTransform (const QTransform & matrix , bool combine = false)

Sets the world transformation matrix. If combine is true, the specified matrix is combined with the current matrix; otherwise it replaces the current matrix.

另请参阅 worldTransform (), transform (),和 setTransform ().

void QPainter:: shear ( qreal sh , qreal sv )

Shears the coordinate system by ( sh , sv ).

另请参阅 setWorldTransform () 和 坐标变换 .

void QPainter:: strokePath (const QPainterPath & path , const QPen & pen )

绘制轮廓 (描边) 路径 path 采用的钢笔指定通过 pen

另请参阅 fillPath () 和 绘制 .

bool QPainter:: testRenderHint ( QPainter::RenderHint hint ) const

返回 true if hint 已设置;否则返回 false .

另请参阅 renderHints () 和 setRenderHint ().

const QTransform &QPainter:: transform () const

别名化的 worldTransform ()。返回世界变换矩阵。

另请参阅 setTransform () 和 worldTransform ().

void QPainter:: translate (const QPointF & offset )

Translates the coordinate system by the given offset ; i.e. the given offset is added to points.

另请参阅 setWorldTransform () 和 坐标变换 .

void QPainter:: translate (const QPoint & offset )

这是重载函数。

Translates the coordinate system by the given offset .

void QPainter:: translate ( qreal dx , qreal dy )

这是重载函数。

Translates the coordinate system by the vector ( dx , dy ).

bool QPainter:: viewTransformEnabled () const

返回 true 若视图变换被启用;否则返回 false。

另请参阅 setViewTransformEnabled () 和 worldTransform ().

QRect QPainter:: viewport () const

返回视口矩形。

另请参阅 setViewport () 和 setViewTransformEnabled ().

QRect QPainter:: window () const

返回窗口矩形。

另请参阅 setWindow () 和 setViewTransformEnabled ().

bool QPainter:: worldMatrixEnabled () const

返回 true 若世界变换被启用;否则返回 false。

另请参阅 setWorldMatrixEnabled (), worldTransform (),和 坐标系统 .

const QTransform &QPainter:: worldTransform () const

返回世界变换矩阵。

另请参阅 setWorldTransform ().