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

Public Functions

QCanvasGridPattern(float x, float y, float width, float height, const int &lineColor, const int &backgroundColor, float lineWidth = 1.0f, float feather = 1.0f, float angle = 0.0f)
~QCanvasGridPattern()
int backgroundColor() const
int cellSize() const
float feather() const
int lineColor() const
float lineWidth() const
float rotation() const
void setBackgroundColor(const int &color)
void setCellSize(float width, float height)
void setCellSize(int size)
void setFeather(float feather)
void setLineColor(const int &color)
void setLineWidth(float width)
void setRotation(float rotation)
void setStartPosition(float x, float y)
void setStartPosition(int point)
int startPosition() const
int &operator<<(int &stream, const QCanvasGridPattern &pattern)
int &operator>>(int &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(float x, float y, float width, float height, const int &lineColor, const int &backgroundColor, 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.

int QCanvasGridPattern::backgroundColor() const

Returns the pattern grid background color.

See also setBackgroundColor().

int 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().

int 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 int &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(int 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 int &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(int 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.

int QCanvasGridPattern::startPosition() const

Returns the start point of grid pattern.

See also setStartPosition().

Related Non-Members

int &operator<<(int &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.

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

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

See also Serializing Qt Data Types.