PySide6.QtCanvasPainter.QCanvasGridPattern

class QCanvasGridPattern

QCanvasGridPattern is a brush for painting grid patterns.

Details

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();
../../_images/gridpattern_example_1.png

Inheritance diagram of PySide6.QtCanvasPainter.QCanvasGridPattern

Synopsis

Methods

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

__init__()

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.

__init__(rect[, lineColor=QColorConstants.White[, backgroundColor=QColorConstants.Black[, lineWidth=1.0f[, feather=1.0f[, angle=0.0f]]]]])
Parameters:
  • rectQRectF

  • lineColorQColor

  • backgroundColorQColor

  • lineWidth – float

  • feather – float

  • angle – float

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.

__init__(x, y, width, height[, lineColor=QColorConstants.White[, backgroundColor=QColorConstants.Black[, lineWidth=1.0f[, feather=1.0f[, angle=0.0f]]]]])
Parameters:
  • x – float

  • y – float

  • width – float

  • height – float

  • lineColorQColor

  • backgroundColorQColor

  • lineWidth – float

  • feather – float

  • angle – float

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.

backgroundColor()
Return type:

QColor

Returns the pattern grid background color.

cellSize()
Return type:

QSizeF

Returns the size of a single cell in grid pattern.

See also

setCellSize()

feather()
Return type:

float

Returns the pattern feather in pixels.

See also

setFeather()

lineColor()
Return type:

QColor

Returns the pattern grid line color.

See also

setLineColor()

lineWidth()
Return type:

float

Returns the width of a stroke line in grid pattern.

See also

setLineWidth()

__ne__(rhs)
Parameters:

rhsQCanvasGridPattern

Return type:

bool

__eq__(rhs)
Parameters:

rhsQCanvasGridPattern

Return type:

bool

rotation()
Return type:

float

Returns the pattern rotation in radians.

See also

setRotation()

setBackgroundColor(color)
Parameters:

colorQColor

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

setCellSize(size)
Parameters:

sizeQSizeF

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

setCellSize(width, height)
Parameters:
  • width – float

  • height – float

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

setFeather(feather)
Parameters:

feather – float

Sets the pattern feather to feather in pixels. The default value is 1.0, meaning a single pixel antialiasing.

See also

feather()

setLineColor(color)
Parameters:

colorQColor

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

See also

lineColor()

setLineWidth(width)
Parameters:

width – float

Sets the width of a stroke line in grid pattern to width. The default value is 1.0.

See also

lineWidth()

setRotation(rotation)
Parameters:

rotation – float

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

setStartPosition(point)
Parameters:

pointQPointF

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

setStartPosition(x, y)
Parameters:
  • x – float

  • y – float

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

startPosition()
Return type:

QPointF

Returns the start point of grid pattern.