- Qt 6.12
- Qt Canvas Painter
- QML Types
- lineargradient2d
- Qt Canvas Painter | Commercial or GPLv3

# lineargradient2d QML Value Type

Provides lineargradient2d type matching to QCanvasLinearGradient. More...

Import Statement: | `import QtCanvas2D`
Since: | Qt 6.12
Status: | Technology preview

This type is in technology preview and is subject to change.

## Methods

- void addColorStop(real offset, string color)
- point endPosition()
- void setEndPosition(real x, real y)
- void setEndPosition(point end)
- void setStartPosition(real x, real y)
- void setStartPosition(point start)
- point startPosition()

## Detailed Description

This value type is provided by the QtCanvas2D import.

See also QCanvasLinearGradient.

## Method Documentation

### void addColorStop(real offset, string color)

Adds a color stop with the given color to the gradient at the given offset. 0.0 is the offset at one end of the gradient, 1.0 is the offset at the other end.

For example:

     const gradient = ctx.createLinearGradient(0, 0, 100, 100);
     gradient.addColorStop(0.0, Qt.rgba(1, 0, 0, 1));
     gradient.addColorStop(0.5, "#ff8040");
     gradient.addColorStop(1.0, "red");

### point endPosition()

Returns the end point of linear gradient.

See also setEndPosition().

### void setEndPosition(real x, real y)

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

See also endPosition().

### void setEndPosition(point end)

Sets the end point of linear gradient to end.

This is an overloaded function.

### void setStartPosition(real x, real y)

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

See also startPosition().

### void setStartPosition(point start)

Sets the start point of linear gradient to start.

This is an overloaded function.

### point startPosition()

Returns the start point of linear gradient.

See also setStartPosition().