在本页

QCanvasGridPattern Class

QCanvasGridPattern 是一种用于绘制网格图案的画笔。更多

Header: #include <QCanvasGridPattern>
CMake: find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)
target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter)
Qt 6.11
继承于 QCanvasBrush
状态:技术预览版

公共函数

QCanvasGridPattern()
QCanvasGridPattern(const QRectF &rect, const QColor &lineColor = QColorConstants::White, const QColor &backgroundColor = QColorConstants::Black, float lineWidth = 1.0f, float feather = 1.0f, float angle = 0.0f)
QCanvasGridPattern(float x, float y, float width, float height, const QColor &lineColor = QColorConstants::White, const QColor &backgroundColor = QColorConstants::Black, float lineWidth = 1.0f, float feather = 1.0f, float angle = 0.0f)
~QCanvasGridPattern()
QColor backgroundColor() const
QSizeF cellSize() const
float feather() const
QColor lineColor() const
float lineWidth() const
float rotation() const
void setBackgroundColor(const QColor &color)
void setCellSize(float width, float height)
void setCellSize(QSizeF size)
void setFeather(float feather)
void setLineColor(const QColor &color)
void setLineWidth(float width)
void setRotation(float rotation)
void setStartPosition(float x, float y)
void setStartPosition(QPointF point)
QPointF startPosition() const
operator QVariant() const
bool operator!=(const QCanvasGridPattern &lhs, const QCanvasGridPattern &rhs)
QDataStream &operator<<(QDataStream &stream, const QCanvasGridPattern &pattern)
bool operator==(const QCanvasGridPattern &lhs, const QCanvasGridPattern &rhs)
QDataStream &operator>>(QDataStream &stream, QCanvasGridPattern &pattern)

详细说明

QCanvasGridPattern 是一种用于绘制网格和条形图案的画笔。

下面是一个简单的示例:

// Rotated grid into background
QRectF rect(20, 20, 180, 180);
QCanvasGridPattern gp1(rect, "#DBEB00", "#373F26");
gp1.setCellSize(16, 16);
gp1.setStartPosition(rect.topLeft());
gp1.setLineWidth(2.0f);
gp1.setRotation(M_PI / 4);
gp1.setFeather(5.0f);
painter.setFillStyle(gp1);
painter.fillRect(rect);
// Rounded rectangle, stroked with
// grid pattern for dashes.
float strokeW = 10;
QRectF rect2(40, 40, 140, 140);
QCanvasGridPattern gp2;
gp2.setLineColor(Qt::transparent);
gp2.setBackgroundColor(Qt::white);
gp2.setStartPosition(rect2.x() - strokeW,
                     rect2.y() - strokeW);
gp2.setCellSize(40, 40);
gp2.setLineWidth(strokeW);
painter.setLineWidth(8);
painter.setStrokeStyle(gp2);
painter.beginPath();
painter.roundRect(rect2, 10);
painter.stroke();

成员函数文档

QCanvasGridPattern::QCanvasGridPattern()

构建默认网格图案。图案起始位置为(0,0),图案大小为(100,100)。图案角度为 0.0,网格线颜色为白色,背景颜色为黑色。

QCanvasGridPattern::QCanvasGridPattern(const QRectF &rect, const QColor &lineColor = QColorConstants::White, const QColor &backgroundColor = QColorConstants::Black, float lineWidth = 1.0f, float feather = 1.0f, float angle = 0.0f)

构建网格图案。图案的起始位置和大小由rect 定义。网格线颜色为lineColor ,背景颜色为backgroundColor 。网格线宽度为lineWidth ,羽化(抗锯齿)为feather ,角度为angle

QCanvasGridPattern::QCanvasGridPattern(float x, float y, float width, float height, const QColor &lineColor = QColorConstants::White, const QColor &backgroundColor = QColorConstants::Black, float lineWidth = 1.0f, float feather = 1.0f, float angle = 0.0f)

构建网格图案。图案起始位置为 (x,y) ,图案大小为 (width,height) 。网格线颜色为lineColor ,背景颜色为backgroundColor 。图案角度为angle

[noexcept] QCanvasGridPattern::~QCanvasGridPattern()

破坏网格模式。

QColor QCanvasGridPattern::backgroundColor() const

返回图案网格的背景颜色。

另请参见 setBackgroundColor()。

QSizeF QCanvasGridPattern::cellSize() const

返回网格图案中单个单元格的大小。

另请参见 setCellSize()。

float QCanvasGridPattern::feather() const

以像素为单位返回图案羽化。

另请参见 setFeather()。

QColor QCanvasGridPattern::lineColor() const

返回图案网格线的颜色。

另请参见 setLineColor()。

float QCanvasGridPattern::lineWidth() const

返回网格图案中描边线的宽度。

另请参见 setLineWidth()。

float QCanvasGridPattern::rotation() const

以弧度为单位返回图案的旋转角度。

另请参见 setRotation()。

void QCanvasGridPattern::setBackgroundColor(const QColor &color)

将图案网格背景颜色设置为color 。默认值为黑色。

另请参阅 backgroundColor() 。

void QCanvasGridPattern::setCellSize(float width, float height)

将网格图案中单个单元格的大小设置为width,height 。宽度为0 时,不绘制水平条形图。高度为0 时,不绘制垂直条形图。默认值为(10, 10)

另请参阅 cellSize() 。

void QCanvasGridPattern::setCellSize(QSizeF size)

将网格图案中单个单元格的大小设置为size 。宽度为0 时,不绘制水平条形图。高度为0 时,不绘制垂直条形图。默认值为(10, 10)

这是一个重载函数。

void QCanvasGridPattern::setFeather(float feather)

将图案羽化设置为feather ,单位为像素。默认值为1.0 ,表示单像素抗锯齿。

另请参阅 feather().

void QCanvasGridPattern::setLineColor(const QColor &color)

将图案网格线颜色设置为color 。默认值为白色。

另请参阅 lineColor() 。

void QCanvasGridPattern::setLineWidth(float width)

将网格图案中笔触线的宽度设置为width 。默认值为1.0

另请参阅 lineWidth() 。

void QCanvasGridPattern::setRotation(float rotation)

将图案旋转设置为rotation ,单位为弧度。旋转围绕网格startPosition() 进行。默认值为0.0 ,表示网格不旋转。

另请参阅 rotation()。

void QCanvasGridPattern::setStartPosition(float x, float y)

将网格图案的起点设置为 (x,y)。起始位置指图案中网格的左上角。然后,图案将从这里扩展到所有位置。默认值为(0.0, 0.0)

另请参见 startPosition()。

void QCanvasGridPattern::setStartPosition(QPointF point)

将网格图案的起点设置为point 。起点位置指图案中网格的左上角。然后,图案将从这里扩展到所有位置。默认值为(0.0, 0.0)

这是一个重载函数。

QPointF QCanvasGridPattern::startPosition() const

返回网格图案的起点。

另请参见 setStartPosition()。

QCanvasGridPattern::operator QVariant() const

QVariant 的形式返回网格图案。

相关非会员

[noexcept] bool operator!=(const QCanvasGridPattern &lhs, const QCanvasGridPattern &rhs)

如果网格模式lhsrhs 不同,则返回true ;否则返回false

另请参见 operator==().

QDataStream &operator<<(QDataStream &stream, const QCanvasGridPattern &pattern)

将给定的pattern 写入给定的stream ,并返回对stream 的引用。

另请参阅 序列化 Qt 数据类型

[noexcept] bool operator==(const QCanvasGridPattern &lhs, const QCanvasGridPattern &rhs)

如果网格模式lhs 等于rhs ,则返回true ;否则返回false

另请参见 operator!=().

QDataStream &operator>>(QDataStream &stream, QCanvasGridPattern &pattern)

从给定的stream 中读取给定的pattern ,并返回对stream 的引用。

另请参阅 序列化 Qt 数据类型

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.