- Qt 6.11
- Qt Canvas Painter
- C++ Classes
- QtCanvasPainter (Technical Preview)
- QCanvasGridPattern
- Qt Canvas Painter | Commercial or GPLv3

# QCanvasGridPattern Class

QCanvasGridPattern is a brush for painting grid patterns. More...

Header: | `#include <QCanvasGridPattern>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)` `target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter)`
Since: | Qt 6.11
Inherits: | QCanvasBrush
Status: | Technical Preview

- List of all members, including inherited members

## Public Functions

| 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

## Related Non-Members

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)

## Detailed Description

QCanvasGridPattern is a brush for painting grid and bar patterns.

Here is a simple example:

     // 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();

## Member Function Documentation

### QCanvasGridPattern::QCanvasGridPattern()

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.

### 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)

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.

### 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)

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]` QCanvasGridPattern::~QCanvasGridPattern()

Destroys the grid pattern.

### QColor QCanvasGridPattern::backgroundColor() const

Returns the pattern grid background color.

See also setBackgroundColor().

### QSizeF QCanvasGridPattern::cellSize() const

Returns the size of a single cell in grid pattern.

See also setCellSize().

### float QCanvasGridPattern::feather() const

Returns the pattern feather in pixels.

See also setFeather().

### QColor QCanvasGridPattern::lineColor() const

Returns the pattern grid line color.

See also setLineColor().

### float QCanvasGridPattern::lineWidth() const

Returns the width of a stroke line in grid pattern.

See also setLineWidth().

### float QCanvasGridPattern::rotation() const

Returns the pattern rotation in radians.

See also setRotation().

### void QCanvasGridPattern::setBackgroundColor(const QColor &color)

Sets the pattern grid background color to color. The default value is black.

See also backgroundColor().

### void QCanvasGridPattern::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 QCanvasGridPattern::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 QCanvasGridPattern::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 QCanvasGridPattern::setLineColor(const QColor &color)

Sets the pattern grid line color to color. The default value is white.

See also lineColor().

### void QCanvasGridPattern::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 QCanvasGridPattern::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 QCanvasGridPattern::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 QCanvasGridPattern::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 QCanvasGridPattern::startPosition() const

Returns the start point of grid pattern.

See also setStartPosition().

### QCanvasGridPattern::operator QVariant() const

Returns the grid pattern as a QVariant.

## Related Non-Members

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

Returns `true` if the grid pattern lhs is different from rhs; `false` otherwise.

See also operator==().

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

Writes the given pattern to the given stream and returns a reference to the stream.

See also Serializing Qt Data Types.

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

Returns `true` if the grid pattern lhs is equal to rhs; `false` otherwise.

See also operator!=().

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

Reads the given pattern from the given stream and returns a reference to the stream.

See also Serializing Qt Data Types.