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 |
| Status: | Technical Preview |
Public Functions
| QCanvasLinearGradient() | |
| QCanvasLinearGradient(float startX, float startY, float endX, float endY) | |
| int | endPosition() const |
| void | setEndPosition(float x, float y) |
| void | setEndPosition(int end) |
| void | setStartPosition(float x, float y) |
| void | setStartPosition(int start) |
| int | 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(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).
int 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(int 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(int start)
Sets the start point of linear gradient to start.
This is an overloaded function.
int QCanvasLinearGradient::startPosition() const
Returns the start point of linear gradient.
See also setStartPosition().
