- Qt 6.12
- Qt Canvas Painter
- QtCanvas2D
- boxgradient2d
- Qt Canvas Painter | Commercial or GPLv3

# boxgradient2d QML Value Type

Provides boxgradient2d type matching to QCanvasBoxGradient. 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)
- real feather()
- real radius()
- rect rect()
- void setFeather(real feather)
- void setRadius(real radius)
- void setRect(x, y, width, height)
- void setRect(rect)

## Detailed Description

This value type is provided by the QtCanvas2D import.

See also QCanvasBoxGradient.

## 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.createBoxGradient(50, 50, 100, 100, 20, 10);
     gradient.addColorStop(0.0, Qt.rgba(1, 0, 0, 1));
     gradient.addColorStop(0.5, "#ff8040");
     gradient.addColorStop(1.0, "red");

### real feather()

Returns the feather of the box gradient.

See also setFeather().

### real radius()

Returns the radius of the box gradient.

See also setRadius().

### rect rect()

Returns the rectangle area of the box gradient.

See also setRect().

### void setFeather(real feather)

Sets the feather of box gradient to feather.

See also feather().

### void setRadius(real radius)

Sets the radius of box gradient to radius. The maximum radius is half of width or height of rect(), depending on which one is smaller.

See also radius().

### void setRect(x, y, width, height)

Sets the rectangle of box gradient to position ( x, y) and size ( width, height).

See also rect().

### void setRect(rect)

Sets the rectangle of box gradient to rect.

This is an overloaded function.