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

# QCanvasBoxGradient Class

QCanvasBoxGradient is a brush for box gradient painting. More...

Header: | `#include <QCanvasBoxGradient>`
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

| QCanvasBoxGradient()
| QCanvasBoxGradient(const QRectF &rect, float feather, float radius = 0.0f)
| QCanvasBoxGradient(float x, float y, float width, float height, float feather, float radius = 0.0f)
| QCanvasBoxGradient(const QCanvasBoxGradient &)
| QCanvasBoxGradient(QCanvasBoxGradient &&)
float | feather() const
float | radius() const
QRectF | rect() const
void | setFeather(float feather)
void | setRadius(float radius)
void | setRect(float x, float y, float width, float height)
void | setRect(const QRectF &rect)
QCanvasBoxGradient & | operator=(QCanvasBoxGradient &&)
QCanvasBoxGradient & | operator=(const QCanvasBoxGradient &)

## Detailed Description

Box gradient interpolate colors between start and end points, creating a rounded rectangle shaped gradient. With the setRadius() and setFeather() the roundness and softness of the gradient can be controlled.

Here is a simple example:

     QRectF rect(20, 20, 160, 160);
     QCanvasBoxGradient bg(rect, 20, 50);
     bg.setColorAt(0.0, "#1a2a6c");
     bg.setColorAt(0.2, "#fdbb2d");
     bg.setColorAt(1.0, QColorConstants::Transparent);
     p->setFillStyle(bg);
     p->fillRect(rect);

Note: When QCanvasBoxGradient is used to paint round rectangle, it is usually better to use QCanvasPainter::rect() than QCanvasPainter::roundRect() as the rounding comes from the brush rather than the path. This avoids creating extra vertices and thus performs better.

## Member Function Documentation

### QCanvasBoxGradient::QCanvasBoxGradient()

Constructs a default box gradient. Position of gradient is (0, 0) and size (100, 100) Gradient feather is 10.0. Gradient radius is 0.0. Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

### QCanvasBoxGradient::QCanvasBoxGradient(const QRectF &rect, float feather, float radius = 0.0f)

Constructs a box gradient. Position and size of gradient is rect. Gradient feather is feather. Gradient radius is radius. Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

### QCanvasBoxGradient::QCanvasBoxGradient(float x, float y, float width, float height, float feather, float radius = 0.0f)

Constructs a box gradient. Position of gradient is ( x, y) and size ( width, height) Gradient feather is feather. Gradient radius is radius. Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

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

Copy-constructs an instance of QCanvasBoxGradient.

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

Move-constructs an instance of QCanvasBoxGradient.

### float QCanvasBoxGradient::feather() const

Returns the feather of the box gradient.

See also setFeather().

### float QCanvasBoxGradient::radius() const

Returns the radius of the box gradient.

See also setRadius().

### QRectF QCanvasBoxGradient::rect() const

Returns the rectangle area of the box gradient.

See also setRect().

### void QCanvasBoxGradient::setFeather(float feather)

Sets the feather of box gradient to feather.

See also feather().

### void QCanvasBoxGradient::setRadius(float 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 QCanvasBoxGradient::setRect(float x, float y, float width, float height)

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

See also rect().

### void QCanvasBoxGradient::setRect(const QRectF &rect)

Sets the rectangle of box gradient to rect.

This is an overloaded function.

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

Move-assigns other to this QCanvasBoxGradient instance.

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

Copy-assigns other to this QCanvasBoxGradient instance.