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

# QCanvasBoxShadow Class

QCanvasBoxShadow is a brush for painting rectangle shadows / glows. More...

Header: | `#include <QCanvasBoxShadow>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)` `target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter)`
Since: | Qt 6.11

- List of all members, including inherited members

## Public Functions

| QCanvasBoxShadow()
| QCanvasBoxShadow(const QRectF &rect)
| QCanvasBoxShadow(qreal x, qreal y, qreal width, qreal height)
| QCanvasBoxShadow(QCanvasBoxShadow &&)
qreal | blur() const
qreal | bottomLeftRadius() const
qreal | bottomRightRadius() const
QRectF | boundingRect() const
QColor | color() const
qreal | radius() const
QRectF | rect() const
void | setBlur(qreal blur)
void | setBottomLeftRadius(qreal radius)
void | setBottomRightRadius(qreal radius)
void | setColor(const QColor &color)
void | setRadius(qreal radius)
void | setRect(qreal x, qreal y, qreal width, qreal height)
void | setRect(const QRectF &rect)
void | setSpread(qreal spread)
void | setTopLeftRadius(qreal radius)
void | setTopRightRadius(qreal radius)
qreal | spread() const
qreal | topLeftRadius() const
qreal | topRightRadius() const

## Related Non-Members

bool | operator!=(const QCanvasBoxShadow &lhs, const QCanvasBoxShadow &rhs)
QDataStream & | operator<<(QDataStream &stream, const QCanvasBoxShadow &shadow)
bool | operator==(const QCanvasBoxShadow &lhs, const QCanvasBoxShadow &rhs)
QDataStream & | operator>>(QDataStream &stream, QCanvasBoxShadow &shadow)

## Detailed Description

QCanvasBoxShadow is a rounded rectangle brush with blur applied. The performance of QCanvasBoxShadow is much better than a general shadow that creates blurred shadow/glow of any shaped item, as it uses SDF approach.

The features of QCanvasBoxShadow are similar to CSS box-shadow, with radius, spread, blur and color values. The rendering output also matches the CSS box-shadow, with few notable differences to make the QCanvasBoxShadow as high-performance as possible. Blurring is calculated mathematically in the shader rather than using Gaussian blur, which CSS box-shadow implementations often use. This makes the shadow look slightly different, especially when the blur amount grows bigger than half of the shadow width / height.

Here are screenshots to compare the rendering output of QCanvasBoxShadow and CSS box-shadow in the Chrome browser. These show how blur radius of 0, 10, 20 and 40 pixels affect smaller shadows.

CSS box-shadow:

QCanvasBoxShadow:

## Member Function Documentation

### QCanvasBoxShadow::QCanvasBoxShadow()

Constructs a default box shadow. The box shadow position is (0, 0) and size (100, 100). Shadow corner radius is `0.0` and blur `0.0`. Shadow color is `Qt::black`.

### `[explicit]` QCanvasBoxShadow::QCanvasBoxShadow(const QRectF &rect)

Constructs a black box shadow with position of rect, and without corner radius or blur.

### QCanvasBoxShadow::QCanvasBoxShadow(qreal x, qreal y, qreal width, qreal height)

Constructs a box shadow with position at x, y and size width, height.

See also blur() and radius().

### `[constexpr noexcept default]` QCanvasBoxShadow::QCanvasBoxShadow(QCanvasBoxShadow &&)

Move-constructs an instance of QCanvasBoxShadow.

### qreal QCanvasBoxShadow::blur() const

Returns the blur of shadow box.

See also setBlur().

### qreal QCanvasBoxShadow::bottomLeftRadius() const

Returns the bottom-left radius of shadow box. When this is `-1`, painting of the shadow will use the value of radius() for this corner. The default value is `-1`.

See also setBottomLeftRadius().

### qreal QCanvasBoxShadow::bottomRightRadius() const

Returns the bottom-right radius of shadow box. When this is `-1`, painting of the shadow will use the value of radius() for this corner. The default value is `-1`.

See also setBottomRightRadius().

### QRectF QCanvasBoxShadow::boundingRect() const

Returns the area covered by the shadow. This takes into account the shadow rect(), blur() and spread(). If you don't want to use QCanvasPainter::drawBoxShadow() helper method, this can be used to for e.g. adding correctly sized QCanvasPainter::rect() into the path.

See also setRect(), setBlur(), and setSpread().

### QColor QCanvasBoxShadow::color() const

Returns the color of shadow box.

See also setColor().

### qreal QCanvasBoxShadow::radius() const

Returns the radius of shadow box.

See also setRadius().

### QRectF QCanvasBoxShadow::rect() const

Returns the rect area of shadow box.

See also setRect().

### void QCanvasBoxShadow::setBlur(qreal blur)

Sets the shadow blur to blur in pixels. The default value is `0.0` meaning no blur.

See also blur().

### void QCanvasBoxShadow::setBottomLeftRadius(qreal radius)

Sets the bottom-left corner radius to radius. The default value is `-1` which means that individual radius has not been set for this corner, and common radius() is used instead.

See also bottomLeftRadius().

### void QCanvasBoxShadow::setBottomRightRadius(qreal radius)

Sets the bottom-right corner radius to radius. The default value is `-1` which means that individual radius has not been set for this corner, and common radius() is used instead.

See also bottomRightRadius().

### void QCanvasBoxShadow::setColor(const QColor &color)

Sets the shadow color to color. The default value is black with full opacity.

See also color().

### void QCanvasBoxShadow::setRadius(qreal radius)

Sets the shadow corner radius to radius in pixels. The default value is `0.0` meaning no radius.

See also radius().

### void QCanvasBoxShadow::setRect(qreal x, qreal y, qreal width, qreal height)

Sets the rect area of shadow box to (x, y, width, height).

See also rect().

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

Sets the rect area of shadow box to rect.

This is an overloaded function.

### void QCanvasBoxShadow::setSpread(qreal spread)

Sets the shadow spread to spread in pixels. The default value is `0.0` meaning no spread.

See also spread().

### void QCanvasBoxShadow::setTopLeftRadius(qreal radius)

Sets the top-left corner radius to radius. The default value is `-1` which means that individual radius has not been set for this corner, and common radius() is used instead.

See also topLeftRadius().

### void QCanvasBoxShadow::setTopRightRadius(qreal radius)

Sets the top-right corner radius to radius. The default value is `-1` which means that individual radius has not been set for this corner, and common radius() is used instead.

See also topRightRadius().

### qreal QCanvasBoxShadow::spread() const

Returns the spread of shadow box.

See also setSpread().

### qreal QCanvasBoxShadow::topLeftRadius() const

Returns the top-left radius of shadow box. When this is `-1`, painting of the shadow will use the value of radius() for this corner. The default value is `-1`.

See also setTopLeftRadius().

### qreal QCanvasBoxShadow::topRightRadius() const

Returns the top-right radius of shadow box. When this is `-1`, painting of the shadow will use the value of radius() for this corner. The default value is `-1`.

See also setTopRightRadius().

## Related Non-Members

### `[noexcept]` bool operator!=(const QCanvasBoxShadow &lhs, const QCanvasBoxShadow &rhs)

Returns `true` if the box shadow lhs is different from rhs; `false` otherwise.

See also operator==().

### QDataStream &operator<<(QDataStream &stream, const QCanvasBoxShadow &shadow)

Writes the given shadow to the given stream and returns a reference to the stream.

See also Serializing Qt Data Types.

### `[noexcept]` bool operator==(const QCanvasBoxShadow &lhs, const QCanvasBoxShadow &rhs)

Returns `true` if the box shadow lhs is equal to rhs; `false` otherwise.

See also operator!=().

### QDataStream &operator>>(QDataStream &stream, QCanvasBoxShadow &shadow)

Reads the given shadow from the given stream and returns a reference to the stream.

See also Serializing Qt Data Types.