QWT 7.0.1
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
QwtPainter Class Reference

A collection of QPainter workarounds. More...

#include <qwt_painter.h>

Static Public Member Functions

static void setPolylineSplitting (bool)
 En/Disable line splitting for the raster paint engine.
 
static bool polylineSplitting ()
 
static void setRoundingAlignment (bool)
 Enable whether coordinates should be rounded, before they are painted to a paint engine that floors to integer values.
 
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 is the application is running with the X11 graphics system that has some special capabilities that can be used for incremental painting to a widget.
 
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)
 填充区域
 
static void fillBackground (QPainter *painter, QWidget *widget, const QVector< QRectF > &fillRects)
 填充widget背景的指定矩形区域
 
static void fillBackground (QPainter *painter, QWidget *canvas)
 自动检测并填充widget的背景
 
static void drawBackgound (QPainter *, const QRectF &, const QWidget *)
 Fill rect with the background of a widget.
 
static void drawCanvasBackgound (QPainter *painter, QWidget *canvas)
 绘制widget的背景
 
static void drawStyledBackground (QWidget *w, QPainter *painter)
 确保widget背景按照当前GUI风格(如Windows、Fusion等)正确绘制
 
static QPixmap backingStore (QWidget *, const QSize &)
 
static qreal devicePixelRatio (const QPaintDevice *)
 
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)
 查找具有可见背景的顶层widget
 

Detailed Description

A collection of QPainter workarounds.

Member Function Documentation

◆ backingStore()

QPixmap QwtPainter::backingStore ( QWidget *  widget,
const QSize &  size 
)
static
Returns
A pixmap that can be used as backing store
Parameters
widgetWidget, for which the backingstore is intended
sizeSize of the pixmap

◆ devicePixelRatio()

qreal QwtPainter::devicePixelRatio ( const QPaintDevice *  paintDevice)
static
Returns
Pixel ratio for a paint device
Parameters
paintDevicePaint device

◆ drawBackgound()

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

Fill rect with the background of a widget.

Parameters
painterPainter
rectRectangle to be filled
widgetWidget
See also
QStyle::PE_Widget, QWidget::backgroundRole()

◆ drawCanvasBackgound()

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

绘制widget的背景

绘制指定canvas widget的背景,支持多种背景类型包括纯色、渐变和纹理模式。 该函数会处理自定义边界路径裁剪和不同背景类型的优化绘制。

Parameters
painter用于绘制的QPainter对象
canvas需要绘制背景的目标widget

绘制过程如下:

  1. 保存当前绘图器状态
  2. 通过反射调用canvas的borderPath方法获取边界路径用于裁剪
  3. 根据背景画刷类型采用不同的绘制策略:
    • 纹理模式:创建临时pixmap并使用fillPixmap填充后绘制
    • 渐变模式:根据渐变坐标模式选择填充裁剪区域或整个矩形
    • 普通模式:直接填充裁剪区域
  4. 恢复绘图器状态
Note
该函数通过Qt的反射机制调用canvas的borderPath方法, 因此canvas类需要提供相应的Q_INVOKABLE方法签名:
Q_INVOKABLE QPainterPath borderPath(const QRect& rect) const;
Warning
如果canvas没有提供borderPath方法,将使用默认矩形边界
See also
QwtPainter::fillPixmap(), QwtPainter::fillRegion(), QWidget::backgroundRole(), QWidget::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.

Parameters
painterPainter
colorMapColor map
intervalValue range
scaleMapScale map
orientationOrientation
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.

Parameters
painterPainter
rectFrame rectangle
palettePalette
foregroundRoleForeground role used for QFrame::Plain
frameWidthFrame width
midLineWidthUsed for QFrame::Box
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.

Parameters
painterPainter
rectFrame rectangle
xRadiusx-radius of the ellipses defining the corners
yRadiusy-radius of the ellipses defining the corners
paletteQPalette::WindowText is used for plain borders QPalette::Dark and QPalette::Light for raised or sunken borders
lineWidthLine width
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.

Parameters
painterPainter
rectFrame rectangle
paletteQPalette::WindowText is used for plain borders QPalette::Dark and QPalette::Light for raised or sunken borders
lineWidthLine width
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.

Parameters
painterPainter
rectTarget rectangle
flagsAlignments/Text flags, see QPainter::drawText()
textText document

◆ drawStyledBackground()

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

确保widget背景按照当前GUI风格(如Windows、Fusion等)正确绘制

支持渐变、纹理、圆角等复杂背景效果

自动适配系统或应用程序的主题设置

Parameters
w
painter

◆ effectivePenWidth()

qreal QwtPainter::effectivePenWidth ( const QPen &  pen)
inlinestatic
Returns
pen.widthF() expanded to at least 1.0
Parameters
penPen

◆ fillBackground() [1/2]

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

自动检测并填充widget的背景

根据widget的样式属性自动检测需要填充的背景区域,并调用相应的填充函数。 支持样式化背景和圆角边框的背景填充。

Parameters
painter用于绘制的QPainter对象
canvas需要填充背景的目标widget

处理逻辑如下:

  1. 如果widget启用了样式化背景(WA_StyledBackground):
    • 使用样式表记录器记录背景绘制信息
    • 如果背景不透明,使用记录的裁剪矩形列表
    • 否则使用整个widget矩形
  2. 如果widget设置了borderRadius属性:
    • 计算四个角的矩形区域作为填充区域
  3. 调用qwtFillBackground进行实际填充
Note
这个函数是背景填充的入口点,会自动选择合适的填充策略
See also
fillBackground(), QwtStyleSheetRecorder

◆ fillBackground() [2/2]

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

填充widget背景的指定矩形区域

使用父级widget的背景来填充当前widget的指定矩形区域列表。 这个函数主要用于处理透明或半透明widget的背景填充优化。

Parameters
painter用于绘制的QPainter对象
widget需要填充背景的目标widget
fillRects需要填充的矩形区域列表

填充过程如下:

  1. 如果填充矩形列表为空,直接返回
  2. 确定裁剪区域:如果painter有裁剪设置则使用变换后的裁剪区域, 否则使用widget的内容区域
  3. 查找能够填充未填充区域的背景widget
  4. 遍历每个填充矩形:
    • 检查是否与裁剪区域相交
    • 创建临时pixmap并使用fillPixmap填充
    • 将pixmap绘制到目标位置
Note
这个函数通常用于处理圆角边框或其他需要局部背景填充的情况
See also
QwtPainter::fillPixmap(), QwtPainter::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 implementation.

Parameters
widgetWidget
pixmapPixmap to be filled
offsetOffset
See also
QPixmap::fill()

◆ fillRegion()

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

填充区域

Parameters
painter
region

◆ findBackgroundWidget()

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

查找具有可见背景的顶层widget

递归地向上遍历widget的父级层次结构,寻找第一个具有不透明背景的widget。 这个函数用于优化绘图操作,避免在透明或无背景的widget上进行不必要的背景绘制。

Parameters
w要检查的起始widget
Returns
返回第一个具有可见背景的widget,如果找不到则返回根widget

查找逻辑如下:

  1. 如果widget没有父级(根widget),直接返回该widget
  2. 如果widget启用了自动背景填充且背景不透明,则返回该widget
  3. 如果widget使用样式化背景,通过实际绘制测试背景是否可见,如果可见则返回
  4. 如果以上条件都不满足,则递归检查父级widget
Note
这个函数主要用于绘图优化,帮助确定在哪里开始绘制背景以避免重复绘制
See also
QWidget::autoFillBackground(), QWidget::backgroundRole(), QWidget::testAttribute()

◆ horizontalAdvance() [1/4]

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

Distance appropriate for drawing a subsequent character after text.

Parameters
fontMetricsFont metrics
textText
Returns
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.

Parameters
fontMetricsFont metrics
chCharacter
Returns
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.

Parameters
fontMetricsFont metrics
textText
Returns
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.

Parameters
fontMetricsFont metrics
chCharacter
Returns
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 beside QPaintEngine::Pdf and QPaintEngine::SVG.

If we have an integer based paint engine it is also checked if the painter has a transformation matrix, that rotates or scales.

Parameters
painterPainter
Returns
true, when the painter is aligning
See also
setRoundingAlignment()

◆ isX11GraphicsSystem()

bool QwtPainter::isX11GraphicsSystem ( )
static

Check is the application is running with the X11 graphics system that has some special capabilities that can be used for incremental painting to a widget.

Returns
True, when the graphics system is X11

◆ polylineSplitting()

bool QwtPainter::polylineSplitting ( )
inlinestatic
Returns
True, when line splitting for the raster paint engine is enabled.
See also
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.

Returns
True, when rounding is enabled
See also
setRoundingAlignment(), isAligning()

◆ roundingAlignment() [2/2]

bool QwtPainter::roundingAlignment ( const QPainter *  painter)
inlinestatic
Returns
roundingAlignment() && isAligning(painter);
Parameters
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.

Parameters
fontUnscaled font
paintDevicePaint device providing a DPI value. If paintDevice == null the DPI value of the primary screen will be used
Returns
Font being adjusted to the DPI value of the paint device

◆ setPolylineSplitting()

void QwtPainter::setPolylineSplitting ( bool  enable)
static

En/Disable line splitting for the raster paint engine.

In some Qt versions the raster paint engine paints polylines of many points much faster when they are split in smaller chunks: f.e all supported Qt versions >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.

Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... ) for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked around in this mode.

The default setting is true.

See also
polylineSplitting()

◆ setRoundingAlignment()

void QwtPainter::setRoundingAlignment ( bool  enable)
static

Enable whether coordinates should be rounded, before they are 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 ( f.e the plot items ).

The default setting is true.

See also
roundingAlignment(), isAligning()

The documentation for this class was generated from the following files: