QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
静态 Public 成员函数 | 所有成员列表
QwtPainter类 参考

A collection of QPainter workarounds 更多...

#include <qwt_painter.h>

静态 Public 成员函数

static void setPolylineSplitting (bool)
 Enable/disable line splitting for the raster paint engine
 
static bool polylineSplitting ()
 
static void setRoundingAlignment (bool)
 Enable/disable coordinate rounding before painting
 
static bool roundingAlignment ()
 Check whether coordinates should be rounded, before they are painted to a paint engine that rounds to integer values.
 
static bool roundingAlignment (const QPainter *)
 
static void drawText (QPainter *, qreal x, qreal y, const QString &)
 Wrapper for QPainter::drawText()
 
static void drawText (QPainter *, const QPointF &, const QString &)
 Wrapper for QPainter::drawText()
 
static void drawText (QPainter *, qreal x, qreal y, qreal w, qreal h, int flags, const QString &)
 Wrapper for QPainter::drawText()
 
static void drawText (QPainter *, const QRectF &, int flags, const QString &)
 Wrapper for QPainter::drawText()
 
static void drawSimpleRichText (QPainter *, const QRectF &, int flags, const QTextDocument &)
 Draw a text document into a rectangle
 
static void drawRect (QPainter *, qreal x, qreal y, qreal w, qreal h)
 Wrapper for QPainter::drawRect()
 
static void drawRect (QPainter *, const QRectF &rect)
 Wrapper for QPainter::drawRect()
 
static void fillRect (QPainter *, const QRectF &, const QBrush &)
 Wrapper for QPainter::fillRect()
 
static void drawEllipse (QPainter *, const QRectF &)
 Wrapper for QPainter::drawEllipse()
 
static void drawPie (QPainter *, const QRectF &r, int a, int alen)
 Wrapper for QPainter::drawPie()
 
static void drawLine (QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
 Wrapper for QPainter::drawLine()
 
static void drawLine (QPainter *, const QPointF &p1, const QPointF &p2)
 Wrapper for QPainter::drawLine()
 
static void drawLine (QPainter *, const QLineF &)
 Wrapper for QPainter::drawLine()
 
static void drawPolygon (QPainter *, const QPolygonF &)
 Wrapper for QPainter::drawPolygon()
 
static void drawPolyline (QPainter *, const QPolygonF &)
 Wrapper for QPainter::drawPolyline()
 
static void drawPolyline (QPainter *, const QPointF *, int pointCount)
 Wrapper for QPainter::drawPolyline()
 
static void drawPolygon (QPainter *, const QPolygon &)
 Wrapper for QPainter::drawPolygon()
 
static void drawPolyline (QPainter *, const QPolygon &)
 Wrapper for QPainter::drawPolyline()
 
static void drawPolyline (QPainter *, const QPoint *, int pointCount)
 Wrapper for QPainter::drawPolyline()
 
static void drawPoint (QPainter *, const QPoint &)
 Wrapper for QPainter::drawPoint()
 
static void drawPoints (QPainter *, const QPolygon &)
 Wrapper for QPainter::drawPoints()
 
static void drawPoints (QPainter *, const QPoint *, int pointCount)
 Wrapper for QPainter::drawPoints()
 
static void drawPoint (QPainter *, qreal x, qreal y)
 Wrapper for QPainter::drawPoint()
 
static void drawPoint (QPainter *, const QPointF &)
 Wrapper for QPainter::drawPoint()
 
static void drawPoints (QPainter *, const QPolygonF &)
 Wrapper for QPainter::drawPoints()
 
static void drawPoints (QPainter *, const QPointF *, int pointCount)
 Wrapper for QPainter::drawPoints()
 
static void drawPath (QPainter *, const QPainterPath &)
 Wrapper for QPainter::drawPath()
 
static void drawImage (QPainter *, const QRectF &, const QImage &)
 Wrapper for QPainter::drawImage()
 
static void drawPixmap (QPainter *, const QRectF &, const QPixmap &)
 Wrapper for QPainter::drawPixmap()
 
static void drawRoundFrame (QPainter *, const QRectF &, const QPalette &, int lineWidth, int frameStyle)
 Draw a round frame
 
static void drawRoundedFrame (QPainter *, const QRectF &, qreal xRadius, qreal yRadius, const QPalette &, int lineWidth, int frameStyle)
 Draw a rectangular frame with rounded borders
 
static void drawFrame (QPainter *, const QRectF &rect, const QPalette &palette, QPalette::ColorRole foregroundRole, int lineWidth, int midLineWidth, int frameStyle)
 Draw a rectangular frame
 
static void drawFocusRect (QPainter *, const QWidget *)
 Draw a focus rectangle on a widget using its style.
 
static void drawFocusRect (QPainter *, const QWidget *, const QRect &)
 Draw a focus rectangle on a widget using its style.
 
static void drawColorBar (QPainter *, const QwtColorMap &, const QwtInterval &, const QwtScaleMap &, Qt::Orientation, const QRectF &)
 Draw a color bar into a rectangle
 
static bool isAligning (const QPainter *)
 Check if the painter is using a paint engine that aligns coordinates to integers
 
static bool isX11GraphicsSystem ()
 Check if the application is running with the X11 graphics system
 
static void fillPixmap (const QWidget *, QPixmap &, const QPoint &offset=QPoint())
 Fill a pixmap with the content of a widget
 
static void fillRegion (QPainter *painter, const QRegion &region)
 Fill a region by drawing all its rectangles
 
static void fillBackground (QPainter *painter, QWidget *widget, const QVector< QRectF > &fillRects)
 Fill specified rectangular areas of a widget with its parent's background
 
static void fillBackground (QPainter *painter, QWidget *canvas)
 Auto-detect and fill a widget's background
 
static void drawBackgound (QPainter *, const QRectF &, const QWidget *)
 Fill rect with the background of a widget
 
static void drawCanvasBackgound (QPainter *painter, QWidget *canvas)
 Draw a widget's canvas background
 
static void drawStyledBackground (QWidget *w, QPainter *painter)
 Ensure widget background is drawn correctly per current GUI style
 
static QPixmap backingStore (QWidget *, const QSize &)
 Create a pixmap that can be used as backing store
 
static qreal devicePixelRatio (const QPaintDevice *)
 Get pixel ratio for a paint device
 
static qreal effectivePenWidth (const QPen &)
 
static int horizontalAdvance (const QFontMetrics &, const QString &)
 Distance appropriate for drawing a subsequent character after text
 
static qreal horizontalAdvance (const QFontMetricsF &, const QString &)
 Distance appropriate for drawing a subsequent character after text
 
static int horizontalAdvance (const QFontMetrics &, QChar)
 Distance appropriate for drawing a subsequent character after ch
 
static qreal horizontalAdvance (const QFontMetricsF &, QChar)
 Distance appropriate for drawing a subsequent character after ch
 
static QFont scaledFont (const QFont &, const QPaintDevice *=nullptr)
 Adjust the DPI value of font according to the DPI value of the paint device
 
static QWidget * findBackgroundWidget (QWidget *w)
 Find the top-level widget with a visible background
 

详细描述

A collection of QPainter workarounds

QwtPainter provides a set of static methods that wrap QPainter operations with workarounds for various Qt rendering issues. It handles device-specific clipping, coordinate rounding, and performance optimizations for different paint engines (raster, SVG, PDF, etc.).

成员函数说明

◆ backingStore()

QPixmap QwtPainter::backingStore ( QWidget *  widget,
const QSize &  size 
)
static

Create a pixmap that can be used as backing store

参数
[in]widgetWidget for which the backing store is intended
[in]sizeSize of the pixmap
返回
Backing store pixmap

◆ devicePixelRatio()

qreal QwtPainter::devicePixelRatio ( const QPaintDevice *  paintDevice)
static

Get pixel ratio for a paint device

参数
[in]paintDevicePaint device
返回
Pixel ratio

◆ drawBackgound()

void QwtPainter::drawBackgound ( QPainter *  painter,
const QRectF &  rect,
const QWidget *  widget 
)
static

Fill rect with the background of a widget

参数
[in]painterPainter
[in]rectRectangle to be filled
[in]widgetWidget
参见
QStyle::PE_Widget, QWidget::backgroundRole()

◆ drawCanvasBackgound()

void QwtPainter::drawCanvasBackgound ( QPainter *  painter,
QWidget *  canvas 
)
static

Draw a widget's canvas background

Draws the background of a canvas widget supporting solid colors, gradients, and texture patterns. Handles custom border path clipping and optimized rendering for different brush types.

参数
[in]painterQPainter for drawing
[in]canvasTarget widget to draw background on

Process:

  1. Save painter state
  2. Invoke borderPath() method via meta-object for clipping
  3. Apply different strategies based on brush type:
    • Texture: create pixmap, fillPixmap, draw
    • Gradient: fill clip region or entire rect based on coordinate mode
    • Plain: fill clip region directly
  4. Restore painter state
注解
Uses Qt meta-object system to call borderPath() method. Canvas class needs Q_INVOKABLE QPainterPath borderPath(const QRect&) const;
警告
If canvas lacks borderPath() method, uses default rect boundary
参见
fillPixmap(), fillRegion(), backgroundRole(), palette()

◆ drawColorBar()

void QwtPainter::drawColorBar ( QPainter *  painter,
const QwtColorMap colorMap,
const QwtInterval interval,
const QwtScaleMap scaleMap,
Qt::Orientation  orientation,
const QRectF &  rect 
)
static

Draw a color bar into a rectangle

Paints to a pixmap first for scalable output in print documents.

参数
[in]painterPainter
[in]colorMapColor map
[in]intervalValue range
[in]scaleMapScale map
[in]orientationOrientation
[in]rectTarget rectangle

◆ drawFrame()

void QwtPainter::drawFrame ( QPainter *  painter,
const QRectF &  rect,
const QPalette &  palette,
QPalette::ColorRole  foregroundRole,
int  frameWidth,
int  midLineWidth,
int  frameStyle 
)
static

Draw a rectangular frame

参数
[in]painterPainter
[in]rectFrame rectangle
[in]palettePalette
[in]foregroundRoleForeground role used for QFrame::Plain
[in]frameWidthFrame width
[in]midLineWidthUsed for QFrame::Box
[in]frameStyleBitwise OR'ed value of QFrame::Shape and QFrame::Shadow

◆ drawRoundedFrame()

void QwtPainter::drawRoundedFrame ( QPainter *  painter,
const QRectF &  rect,
qreal  xRadius,
qreal  yRadius,
const QPalette &  palette,
int  lineWidth,
int  frameStyle 
)
static

Draw a rectangular frame with rounded borders

参数
[in]painterPainter
[in]rectFrame rectangle
[in]xRadiusX-radius of the ellipses defining the corners
[in]yRadiusY-radius of the ellipses defining the corners
[in]paletteQPalette::WindowText for plain borders, QPalette::Dark and QPalette::Light for raised/sunken
[in]lineWidthLine width
[in]frameStyleBitwise OR'ed value of QFrame::Shape and QFrame::Shadow

◆ drawRoundFrame()

void QwtPainter::drawRoundFrame ( QPainter *  painter,
const QRectF &  rect,
const QPalette &  palette,
int  lineWidth,
int  frameStyle 
)
static

Draw a round frame

参数
[in]painterPainter
[in]rectFrame rectangle
[in]paletteQPalette::WindowText is used for plain borders, QPalette::Dark and QPalette::Light for raised/sunken borders
[in]lineWidthLine width
[in]frameStyleBitwise OR'ed value of QFrame::Shape and QFrame::Shadow

◆ drawSimpleRichText()

void QwtPainter::drawSimpleRichText ( QPainter *  painter,
const QRectF &  rect,
int  flags,
const QTextDocument &  text 
)
static

Draw a text document into a rectangle

参数
[in]painterPainter
[in]rectTarget rectangle
[in]flagsAlignments/Text flags, see QPainter::drawText()
[in]textText document

◆ drawStyledBackground()

void QwtPainter::drawStyledBackground ( QWidget *  w,
QPainter *  painter 
)
static

Ensure widget background is drawn correctly per current GUI style

Supports gradients, textures, rounded corners and other complex effects. Automatically adapts to system or application theme settings.

参数
[in]wWidget to draw background for
[in]painterQPainter for drawing

◆ effectivePenWidth()

qreal QwtPainter::effectivePenWidth ( const QPen &  pen)
inlinestatic
返回
pen.widthF() expanded to at least 1.0
参数
penPen

◆ fillBackground() [1/2]

void QwtPainter::fillBackground ( QPainter *  painter,
QWidget *  canvas 
)
static

Auto-detect and fill a widget's background

Detects background areas based on widget style properties and applies appropriate fill strategy. Supports styled backgrounds and rounded borders.

参数
[in]painterQPainter for drawing
[in]canvasTarget widget needing background fill

Logic:

  1. If WA_StyledBackground is enabled: use stylesheet recorder to detect areas, use clipRects if opaque, otherwise use entire widget rect
  2. If borderRadius property is set: calculate four corner rect areas
  3. Call fillBackground() for actual filling
注解
Entry point for background filling, auto-selects appropriate strategy
参见
fillBackground(), QwtStyleSheetRecorder

◆ fillBackground() [2/2]

void QwtPainter::fillBackground ( QPainter *  painter,
QWidget *  widget,
const QVector< QRectF > &  fillRects 
)
static

Fill specified rectangular areas of a widget with its parent's background

This function handles background filling optimization for transparent or semi-transparent widgets.

参数
[in]painterQPainter for drawing
[in]widgetTarget widget needing background fill
[in]fillRectsList of rectangular areas to fill

Process:

  1. Return if fillRects is empty
  2. Determine clip region from painter or widget's content rect
  3. Find background widget that can fill unfilled areas
  4. For each fill rect: check intersection, create pixmap, fill, draw
注解
Typically used for rounded borders or partial background filling
参见
fillPixmap(), findBackgroundWidget()

◆ fillPixmap()

void QwtPainter::fillPixmap ( const QWidget *  widget,
QPixmap &  pixmap,
const QPoint &  offset = QPoint() 
)
static

Fill a pixmap with the content of a widget

In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy for backgrounds with gradients. Thus fillPixmap() offers an alternative.

参数
[in]widgetWidget
[out]pixmapPixmap to be filled
[in]offsetOffset
参见
QPixmap::fill()

◆ fillRegion()

void QwtPainter::fillRegion ( QPainter *  painter,
const QRegion &  region 
)
static

Fill a region by drawing all its rectangles

参数
[in]painterPainter
[in]regionRegion to fill

◆ findBackgroundWidget()

QWidget * QwtPainter::findBackgroundWidget ( QWidget *  w)
static

Find the top-level widget with a visible background

Recursively traverses up the widget hierarchy to find the first widget with an opaque background. Used to optimize drawing operations by avoiding unnecessary background painting on transparent widgets.

参数
[in]wStarting widget to check
返回
First widget with visible background, or root widget if none found

Logic:

  1. If widget has no parent (root widget), return it
  2. If autoFillBackground is enabled and background is opaque, return it
  3. If WA_StyledBackground is set, test by actual drawing, return if visible
  4. Otherwise, recursively check parent widget
注解
Used for drawing optimization to determine where to start background drawing
参见
autoFillBackground(), backgroundRole(), testAttribute()

◆ horizontalAdvance() [1/4]

int QwtPainter::horizontalAdvance ( const QFontMetrics &  fontMetrics,
const QString &  text 
)
static

Distance appropriate for drawing a subsequent character after text

参数
[in]fontMetricsFont metrics
[in]textText
返回
Horizontal advance in pixels

◆ horizontalAdvance() [2/4]

int QwtPainter::horizontalAdvance ( const QFontMetrics &  fontMetrics,
QChar  ch 
)
static

Distance appropriate for drawing a subsequent character after ch

参数
[in]fontMetricsFont metrics
[in]chCharacter
返回
Horizontal advance in pixels

◆ horizontalAdvance() [3/4]

qreal QwtPainter::horizontalAdvance ( const QFontMetricsF &  fontMetrics,
const QString &  text 
)
static

Distance appropriate for drawing a subsequent character after text

参数
[in]fontMetricsFont metrics
[in]textText
返回
Horizontal advance in pixels

◆ horizontalAdvance() [4/4]

qreal QwtPainter::horizontalAdvance ( const QFontMetricsF &  fontMetrics,
QChar  ch 
)
static

Distance appropriate for drawing a subsequent character after ch

参数
[in]fontMetricsFont metrics
[in]chCharacter
返回
Horizontal advance in pixels

◆ isAligning()

bool QwtPainter::isAligning ( const QPainter *  painter)
static

Check if the painter is using a paint engine that aligns coordinates to integers

Today these are all paint engines except QPaintEngine::Pdf and QPaintEngine::SVG. If we have an integer-based paint engine, it is also checked whether the painter has a transformation matrix that rotates or scales.

参数
[in]painterPainter to check
返回
True when the painter is aligning
参见
setRoundingAlignment()

◆ isX11GraphicsSystem()

bool QwtPainter::isX11GraphicsSystem ( )
static

Check if the application is running with the X11 graphics system

The X11 graphics system has special capabilities for incremental painting. With Qt 5.10+, X11 paint engine can be enabled via QT_XCB_NATIVE_PAINTING=1.

返回
True when the graphics system is X11

◆ polylineSplitting()

bool QwtPainter::polylineSplitting ( )
inlinestatic
返回
True, when line splitting for the raster paint engine is enabled.
参见
setPolylineSplitting()

◆ roundingAlignment() [1/2]

bool QwtPainter::roundingAlignment ( )
inlinestatic

Check whether coordinates should be rounded, before they are painted to a paint engine that rounds to integer values.

For other paint engines ( PDF, SVG ), this flag has no effect.

返回
True, when rounding is enabled
参见
setRoundingAlignment(), isAligning()

◆ roundingAlignment() [2/2]

bool QwtPainter::roundingAlignment ( const QPainter *  painter)
inlinestatic
返回
roundingAlignment() && isAligning(painter);
参数
painterPainter

◆ scaledFont()

QFont QwtPainter::scaledFont ( const QFont &  font,
const QPaintDevice *  paintDevice = nullptr 
)
static

Adjust the DPI value of font according to the DPI value of the paint device

参数
[in]fontUnscaled font
[in]paintDevicePaint device providing a DPI value. If null, primary screen DPI is used
返回
Font adjusted to the DPI value of the paint device

◆ setPolylineSplitting()

void QwtPainter::setPolylineSplitting ( bool  enable)
static

Enable/disable line splitting for the raster paint engine

In some Qt versions, the raster paint engine paints polylines much faster when split into smaller chunks. Also works around a bug for short lines in many Qt versions (Qt 4.8+).

参数
[in]enableEnable/disable splitting
参见
polylineSplitting()

◆ setRoundingAlignment()

void QwtPainter::setRoundingAlignment ( bool  enable)
static

Enable/disable coordinate rounding before painting

Coordinates are rounded before being painted to a paint engine that floors to integer values. For other paint engines (PDF, SVG), this flag has no effect. QwtPainter stores this flag only; the rounding itself is done in the painting code.

参数
[in]enableEnable/disable rounding
参见
roundingAlignment(), isAligning()

该类的文档由以下文件生成: