QCGridPattern Class
QCGridPattern is a brush for painting grid patterns. More...
| Header: | #include <QCGridPattern> |
| Inherits: | QCBrush |
Public Functions
| QCGridPattern() | |
| QCGridPattern(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) | |
| QCGridPattern(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) | |
| ~QCGridPattern() | |
| 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 |
| QVariant | operator QVariant() const |
| bool | operator!=(const QCGridPattern &pattern) const |
| bool | operator==(const QCGridPattern &pattern) const |
Related Non-Members
| QDataStream & | operator<<(QDataStream &stream, const QCGridPattern &pattern) |
| QDataStream & | operator>>(QDataStream &stream, QCGridPattern &pattern) |
Detailed Description
QCGridPattern is a brush for painting grid and bar patterns.
Here is a simple example:
// Rotated grid into background QRectF rect(20, 20, 180, 180); QCGridPattern 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); QCGridPattern 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();

Member Function Documentation
QCGridPattern::QCGridPattern()
Constructs a default grid pattern. Pattern start position position is (0, 0) and pattern size (100, 100). Pattern angle is 0.0, grid line color white and background color black.
QCGridPattern::QCGridPattern(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)
Constructs an grid pattern. Pattern start position position and size is defined with rect. Grid line color is lineColor and background color is backgroundColor. Grid line width is lineWidth, feather (antialiasing) is feather and angle is angle.
QCGridPattern::QCGridPattern(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)
Constructs an grid pattern. Pattern start position is ( x, y) and pattern size ( width, height). Grid line color is lineColor and background color is backgroundColor. Pattern angle is angle.
[noexcept] QCGridPattern::~QCGridPattern()
Destroys the grid pattern.
QColor QCGridPattern::backgroundColor() const
Returns the pattern grid background color.
See also setBackgroundColor().
QSizeF QCGridPattern::cellSize() const
Returns the size of a single cell in grid pattern.
See also setCellSize().
float QCGridPattern::feather() const
Returns the pattern feather in pixels.
See also setFeather().
QColor QCGridPattern::lineColor() const
Returns the pattern grid line color.
See also setLineColor().
float QCGridPattern::lineWidth() const
Returns the width of a stroke line in grid pattern.
See also setLineWidth().
float QCGridPattern::rotation() const
Returns the pattern rotation in radians.
See also setRotation().
void QCGridPattern::setBackgroundColor(const QColor &color)
Sets the pattern grid background color to color. The default value is black.
See also backgroundColor().
void QCGridPattern::setCellSize(float width, float height)
Sets the size of a single cell in grid pattern to width, height. When width is 0, the horizontal bars are not painted. When height is 0, the vertical bars are not painted. The default value is (10, 10).
See also cellSize().
void QCGridPattern::setCellSize(QSizeF size)
Sets the size of a single cell in grid pattern to size. When width is 0, the horizontal bars are not painted. When height is 0, the vertical bars are not painted. The default value is (10, 10).
This is an overloaded function.
void QCGridPattern::setFeather(float feather)
Sets the pattern feather to feather in pixels. The default value is 1.0, meaning a single pixel antialiasing.
See also feather().
void QCGridPattern::setLineColor(const QColor &color)
Sets the pattern grid line color to color. The default value is white.
See also lineColor().
void QCGridPattern::setLineWidth(float width)
Sets the width of a stroke line in grid pattern to width. The default value is 1.0.
See also lineWidth().
void QCGridPattern::setRotation(float rotation)
Sets the pattern rotation to rotation in radians. Rotation is done around the grid startPosition(). The default value is 0.0, meaning the grid is not rotated.
See also rotation().
void QCGridPattern::setStartPosition(float x, float y)
Sets the start point of grid pattern to (x, y). Start position means top-left corner of the grid in pattern. Pattern will then be extended to all positions from here. The default value is (0.0, 0.0).
See also startPosition().
void QCGridPattern::setStartPosition(QPointF point)
Sets the start point of grid pattern to point. Start position means top-left corner of the grid in pattern. Pattern will then be extended to all positions from here. The default value is (0.0, 0.0).
This is an overloaded function.
QPointF QCGridPattern::startPosition() const
Returns the start point of grid pattern.
See also setStartPosition().
QVariant QCGridPattern::operator QVariant() const
Returns the grid pattern as a QVariant.
bool QCGridPattern::operator!=(const QCGridPattern &pattern) const
Returns true if the grid pattern is different from the given pattern; otherwise false.
See also operator==().
bool QCGridPattern::operator==(const QCGridPattern &pattern) const
Returns true if the grid pattern is equal to the given pattern; otherwise false.
See also operator!=().
Related Non-Members
QDataStream &operator<<(QDataStream &stream, const QCGridPattern &pattern)
Writes the given pattern to the given stream and returns a reference to the stream.
See also Serializing Qt Data Types.
QDataStream &operator>>(QDataStream &stream, QCGridPattern &pattern)
Reads the given pattern from the given stream and returns a reference to the stream.
See also Serializing Qt Data Types.
© 2025 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.