On this page

QCanvasLinearGradient Class

QCanvasLinearGradient is a brush for linear gradient painting. More...

Header: #include <QCanvasLinearGradient>
CMake: find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)
target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter)
Since: Qt 6.11
Inherits: QCanvasGradient

Public Functions

QCanvasLinearGradient()
QCanvasLinearGradient(QPointF start, QPointF end)
QCanvasLinearGradient(float startX, float startY, float endX, float endY)
QPointF endPosition() const
void setEndPosition(float x, float y)
void setEndPosition(QPointF end)
void setStartPosition(float x, float y)
void setStartPosition(QPointF start)
QPointF startPosition() const

Detailed Description

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.

Here is a simple example:

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

Member Function Documentation

QCanvasLinearGradient::QCanvasLinearGradient()

Constructs a default linear gradient. Gradient start color position is (0, 0) and end color position (0, 100). Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

QCanvasLinearGradient::QCanvasLinearGradient(QPointF start, QPointF end)

Constructs a linear gradient. Gradient start color position is start and end color position end. Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

QCanvasLinearGradient::QCanvasLinearGradient(float startX, float startY, float endX, float endY)

Constructs a linear gradient. Gradient start color position is (startX, startY) and end color position (endX, endY). Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

QPointF QCanvasLinearGradient::endPosition() const

Returns the end point of linear gradient.

See also setEndPosition().

void QCanvasLinearGradient::setEndPosition(float x, float y)

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

See also endPosition().

void QCanvasLinearGradient::setEndPosition(QPointF end)

Sets the end point of linear gradient to end.

This is an overloaded function.

void QCanvasLinearGradient::setStartPosition(float x, float y)

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

See also startPosition().

void QCanvasLinearGradient::setStartPosition(QPointF start)

Sets the start point of linear gradient to start.

This is an overloaded function.

QPointF QCanvasLinearGradient::startPosition() const

Returns the start point of linear gradient.

See also setStartPosition().

© 2026 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.