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 |
Public Functions
| QCanvasBoxGradient(const int &rect) | |
| QCanvasBoxGradient(int x, int y, int width, int height) | |
| QCanvasBoxGradient(const QCanvasBoxGradient &) | |
| QCanvasBoxGradient(QCanvasBoxGradient &&) | |
| ~QCanvasBoxGradient() | |
| int | feather() const |
| int | radius() const |
| int | rect() const |
| void | setFeather(int feather) |
| void | setRadius(int radius) |
| void | setRect(int x, int y, int width, int height) |
| void | setRect(const int &rect) |
| void | swap(QCanvasBoxGradient &other) |
| 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:
![]() |
|
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(const int &rect)
Constructs a box gradient. Position and size of gradient is rect. Gradient feather is 10.0 and radius is 0.0.
See also setFeather() and setRadius().
QCanvasBoxGradient::QCanvasBoxGradient(int x, int y, int width, int height)
Constructs a box gradient. Position of gradient is ( x, y) and size ( width, height) Gradient feather is 10.0 and radius is 0.0.
See also setFeather() and setRadius().
[constexpr noexcept default] QCanvasBoxGradient::QCanvasBoxGradient(const QCanvasBoxGradient &)
Copy-constructs an instance of QCanvasBoxGradient.
[constexpr noexcept default] QCanvasBoxGradient::QCanvasBoxGradient(QCanvasBoxGradient &&)
Move-constructs an instance of QCanvasBoxGradient.
[constexpr noexcept default] QCanvasBoxGradient::~QCanvasBoxGradient()
Destroys the instance of QCanvasBoxGradient.
int QCanvasBoxGradient::feather() const
Returns the feather of the box gradient.
See also setFeather().
int QCanvasBoxGradient::radius() const
Returns the radius of the box gradient.
See also setRadius().
int QCanvasBoxGradient::rect() const
Returns the rectangle area of the box gradient.
See also setRect().
void QCanvasBoxGradient::setFeather(int feather)
Sets the feather of box gradient to feather.
See also feather().
void QCanvasBoxGradient::setRadius(int 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(int x, int y, int width, int height)
Sets the rectangle of box gradient to position ( x, y) and size ( width, height).
See also rect().
void QCanvasBoxGradient::setRect(const int &rect)
Sets the rectangle of box gradient to rect.
This is an overloaded function.
[noexcept] void QCanvasBoxGradient::swap(QCanvasBoxGradient &other)
Swaps this gradient with other. This operation is very fast and never fails.
[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.
