PySide6.QtCanvasPainter.QCanvasLinearGradient

class QCanvasLinearGradient

QCanvasLinearGradient is a brush for linear gradient painting.

Details

Liner gradient interpolate colors between start and end points along a linear pattern, so horizontally, vertically or diagonally. The gradient starts from startPosition() and ends to endPosition(). Outside this area, the colors are the starting and the ending color.

../../_images/qclineargradient-gallery.webp

Here is a simple example:

qclineargradient-example1

QRectF rect1(0, 0, 200, 200);
QCanvasLinearGradient lg(rect1.topLeft(),
                    rect1.bottomRight());
lg.setColorAt(0.0, "#1a2a6c");
lg.setColorAt(0.5, "#b21f1f");
lg.setColorAt(1.0, "#fdbb2d");
p->setFillStyle(lg);
p->fillRect(rect1);

Inheritance diagram of PySide6.QtCanvasPainter.QCanvasLinearGradient

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 linear gradient. Gradient start color position is (0, 0) and end color position (0, 100).

__init__(arg__1)
Parameters:

arg__1 – QCanvasLinearGradient

Copy-constructs an instance of QCanvasLinearGradient.

__init__(start, end)
Parameters:

Constructs a linear gradient. Gradient start color position is start and end color position end.

__init__(startX, startY, endX, endY)
Parameters:
  • startX – float

  • startY – float

  • endX – float

  • endY – float

Constructs a linear gradient. Gradient start color position is (startX, startY) and end color position (endX, endY).

endPosition()
Return type:

QPointF

Returns the end point of linear gradient.

See also

setEndPosition()

setEndPosition(end)
Parameters:

end – QPointF

Sets the end point of linear gradient to end.

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

  • y – float

Sets the end point of linear gradient to ( x, y).

See also

endPosition()

setStartPosition(start)
Parameters:

start – QPointF

Sets the start point of linear gradient to start.

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

  • y – float

Sets the start point of linear gradient to ( x, y).

See also

startPosition()

startPosition()
Return type:

QPointF

Returns the start point of linear gradient.

swap(other)
Parameters:

other – QCanvasLinearGradient

Swaps this gradient with other. This operation is very fast and never fails.