QCanvasGridPattern Class
QCanvasGridPattern 是一款用于绘制网格图案的画笔。更多内容...
| 标题: | #include <QCanvasGridPattern> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS CanvasPainter) target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter) |
| 自: | Qt 6.11 |
公共函数
| QCanvasGridPattern(QPointF startPosition, QSizeF cellSize) | |
| QCanvasGridPattern(qreal startX, qreal startY, qreal cellWidth, qreal cellHeight) | |
| QCanvasGridPattern(const QCanvasGridPattern &) | |
| QCanvasGridPattern(QCanvasGridPattern &&) | |
| QColor | backgroundColor() const |
| QSizeF | cellSize() const |
| qreal | feather() const |
| QColor | lineColor() const |
| qreal | lineWidth() const |
| qreal | rotation() const |
| void | setBackgroundColor(QColor color) |
| void | setCellSize(qreal width, qreal height) |
| void | setCellSize(QSizeF size) |
| void | setFeather(qreal feather) |
| void | setLineColor(QColor color) |
| void | setLineWidth(qreal width) |
| void | setRotation(qreal rotation) |
| void | setStartPosition(qreal x, qreal 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.topLeft(), QSizeF(16, 16));
gp1.setLineColor("#DBEB00");
gp1.setBackgroundColor("#373F26");
gp1.setLineWidth(2.0);
gp1.setRotation(M_PI / 4);
gp1.setFeather(5.0);
painter.setFillStyle(gp1);
painter.fillRect(rect);
// Rounded rectangle, stroked with
// grid pattern for dashes.
qreal 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(QPointF startPosition, QSizeF cellSize)
构建一个从startPosition 开始的网格图案,每个网格单元的大小为cellSize 。
另请参阅 setStartPosition() 和setCellSize()。
QCanvasGridPattern::QCanvasGridPattern(qreal startX, qreal startY, qreal cellWidth, qreal cellHeight)
构建一个网格图案,起始坐标为startX 和startY ,单个网格单元大小为cellWidth 和cellHeight 。
另请参阅 setLineColor()、setBackgroundColor()、setLineWidth()、setFeather() 以及setRotation()。
QCanvasGridPattern::QCanvasGridPattern(const QCanvasGridPattern &)
破坏了网格图案。
[constexpr noexcept default] QCanvasGridPattern::QCanvasGridPattern(QCanvasGridPattern &&)
通过move操作构造一个QCanvasGridPattern 实例。
QColor QCanvasGridPattern::backgroundColor() const
返回图案网格的背景色。
另请参阅 setBackgroundColor()。
QSizeF QCanvasGridPattern::cellSize() const
返回网格中单个单元格的大小。
另请参阅 setCellSize()。
qreal QCanvasGridPattern::feather() const
返回以像素为单位的羽毛图案。
另请参阅 setFeather()。
QColor QCanvasGridPattern::lineColor() const
返回图案网格线的颜色。
另请参阅 ` setLineColor()`。
qreal QCanvasGridPattern::lineWidth() const
返回网格图案中笔画的宽度。
另请参阅 setLineWidth()。
qreal QCanvasGridPattern::rotation() const
返回图案的旋转角度(单位为弧度)。
另请参阅 setRotation()。
void QCanvasGridPattern::setBackgroundColor(QColor color)
将图案网格的背景色设置为color 。默认值为黑色。
另请参阅 backgroundColor()。
void QCanvasGridPattern::setCellSize(qreal width, qreal height)
将网格模式下单个单元格的大小设置为width ,height 。当 width 为0 时,不会绘制水平条;当 height 为0 时,不会绘制垂直条。默认值为(10, 10) 。
另请参阅 cellSize()。
void QCanvasGridPattern::setCellSize(QSizeF size)
将网格模式中单个单元格的大小设置为size 。当width为0 时,不会绘制水平条;当height为0 时,不会绘制垂直条。默认值为(10, 10) 。
这是一个重载函数。
void QCanvasGridPattern::setFeather(qreal feather)
将图案羽化设置为feather (单位为像素)。默认值为1.0 ,表示单像素抗锯齿。
另请参阅 feather()。
void QCanvasGridPattern::setLineColor(QColor color)
将图案网格线的颜色设置为color 。默认值为白色。
另请参阅 lineColor()。
void QCanvasGridPattern::setLineWidth(qreal width)
将网格图案中线条的宽度设置为width 。默认值为1.0 。
另请参阅 lineWidth()。
void QCanvasGridPattern::setRotation(qreal rotation)
将图案旋转角度设置为rotation (单位:弧度)。旋转以网格startPosition()为中心进行。默认值为0.0 ,表示网格不进行旋转。
另请参阅 rotation()。
void QCanvasGridPattern::setStartPosition(qreal x, qreal 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)
如果网格模式lhs 与rhs 不一致,则返回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.