- Qt 6.12
- Qt Canvas Painter
- C++ Classes
- QCanvasLinearGradient
- Qt Canvas Painter | Commercial or GPLv3

# 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

- List of all members, including inherited members

## Public Functions

| QCanvasLinearGradient()
| QCanvasLinearGradient(QPointF start, QPointF end)
| QCanvasLinearGradient(float startX, float startY, float endX, float endY)
| QCanvasLinearGradient(const QCanvasLinearGradient &)
| QCanvasLinearGradient(QCanvasLinearGradient &&)
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
QCanvasLinearGradient & | operator=(QCanvasLinearGradient &&)
QCanvasLinearGradient & | operator=(const QCanvasLinearGradient &)

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

### `[noexcept default]` QCanvasLinearGradient::QCanvasLinearGradient(const QCanvasLinearGradient &)

Copy-constructs an instance of QCanvasLinearGradient.

### `[noexcept default]` QCanvasLinearGradient::QCanvasLinearGradient(QCanvasLinearGradient &&)

Move-constructs an instance of QCanvasLinearGradient.

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

### `[noexcept default]` QCanvasLinearGradient &QCanvasLinearGradient::operator=(QCanvasLinearGradient &&)

Move-assigns other to this QCanvasLinearGradient instance.

### `[noexcept default]` QCanvasLinearGradient &QCanvasLinearGradient::operator=(const QCanvasLinearGradient &)

Copy-assigns other to this QCanvasLinearGradient instance.