QCBoxShadow Class
QCBoxShadow is a brush for painting rectangle shadows / glows. More...
| Header: | #include <QCBoxShadow> |
| Inherits: | QCBrush |
Public Functions
| QCBoxShadow() | |
| QCBoxShadow(const QRectF &rect, float radius = 0.0f, float blur = 0.0f, const QColor &color = QColorConstants::Black) | |
| QCBoxShadow(float x, float y, float width, float height, float radius = 0.0f, float blur = 0.0f, const QColor &color = QColorConstants::Black) | |
| QCBoxShadow(const QCBoxShadow &shadow) | |
| QCBoxShadow(QCBoxShadow &&other) | |
| virtual | ~QCBoxShadow() |
| float | blur() const |
| float | bottomLeftRadius() const |
| float | bottomRightRadius() const |
| QRectF | boundingRect() const |
| QColor | color() const |
| float | radius() const |
| QRectF | rect() const |
| void | setBlur(float blur) |
| void | setBottomLeftRadius(float radius) |
| void | setBottomRightRadius(float radius) |
| void | setColor(const QColor &color) |
| void | setRadius(float radius) |
| void | setRect(const QRectF &rect) |
| void | setRect(float x, float y, float width, float height) |
| void | setSpread(float spread) |
| void | setTopLeftRadius(float radius) |
| void | setTopRightRadius(float radius) |
| float | spread() const |
| void | swap(QCBoxShadow &other) |
| float | topLeftRadius() const |
| float | topRightRadius() const |
| QVariant | operator QVariant() const |
| bool | operator!=(const QCBoxShadow &shadow) const |
| QCBoxShadow & | operator=(QCBoxShadow &&other) |
| QCBoxShadow & | operator=(const QCBoxShadow &shadow) |
| bool | operator==(const QCBoxShadow &shadow) const |
Reimplemented Public Functions
| virtual QCBrush::BrushType | type() const override |
Related Non-Members
| QDataStream & | operator<<(QDataStream &stream, const QCBoxShadow &shadow) |
| QDataStream & | operator>>(QDataStream &stream, QCBoxShadow &shadow) |
Detailed Description
QCBoxShadow is a rounded rectangle brush with blur applied. The performance of QCBoxShadow is much better than a general shadow that creates blurred shadow/glow of any shaped item, as it uses SDF approach.
The features of QCBoxShadow 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 QCBoxShadow 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 QCBoxShadow 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:

QCBoxShadow:

Member Function Documentation
QCBoxShadow::QCBoxShadow()
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.
QCBoxShadow::QCBoxShadow(const QRectF &rect, float radius = 0.0f, float blur = 0.0f, const QColor &color = QColorConstants::Black)
Constructs a box shadow. The box shadow position and size are defined by rect. Shadow corner radius is radius and blur blur. Shadow color is color.
QCBoxShadow::QCBoxShadow(float x, float y, float width, float height, float radius = 0.0f, float blur = 0.0f, const QColor &color = QColorConstants::Black)
Constructs a box shadow. The box shadow position is x, y and size width, height. Shadow corner radius is radius and blur blur. Shadow color is color.
[noexcept] QCBoxShadow::QCBoxShadow(const QCBoxShadow &shadow)
Constructs a box shadow that is a copy of the given shadow.
[constexpr noexcept] QCBoxShadow::QCBoxShadow(QCBoxShadow &&other)
Move-constructs a new QCBoxShadow from other.
[virtual noexcept] QCBoxShadow::~QCBoxShadow()
Destroys the box shadow.
float QCBoxShadow::blur() const
Returns the blur of shadow box.
See also setBlur().
float QCBoxShadow::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().
float QCBoxShadow::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 QCBoxShadow::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 QCPainter::drawBoxShadow() helper method, this can be used to for e.g. adding correctly sized QCPainter::rect() into the path.
See also setRect(), setBlur(), and setSpread().
QColor QCBoxShadow::color() const
Returns the color of shadow box.
See also setColor().
float QCBoxShadow::radius() const
Returns the radius of shadow box.
See also setRadius().
QRectF QCBoxShadow::rect() const
Returns the rect area of shadow box.
See also setRect().
void QCBoxShadow::setBlur(float blur)
Sets the shadow blur to blur in pixels. The default value is 0.0 meaning no blur.
See also blur().
void QCBoxShadow::setBottomLeftRadius(float 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 QCBoxShadow::setBottomRightRadius(float 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 QCBoxShadow::setColor(const QColor &color)
Sets the shadow color to color. The default value is black with full opacity.
See also color().
void QCBoxShadow::setRadius(float radius)
Sets the shadow corner radius to radius in pixels. The default value is 0.0 meaning no radius.
See also radius().
void QCBoxShadow::setRect(const QRectF &rect)
Sets the rect area of shadow box to rect.
See also rect().
void QCBoxShadow::setRect(float x, float y, float width, float height)
Sets the rect area of shadow box to (x, y, width, height).
See also rect().
void QCBoxShadow::setSpread(float spread)
Sets the shadow spread to spread in pixels. The default value is 0.0 meaning no spread.
See also spread().
void QCBoxShadow::setTopLeftRadius(float 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 QCBoxShadow::setTopRightRadius(float 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().
float QCBoxShadow::spread() const
Returns the spread of shadow box.
See also setSpread().
[noexcept] void QCBoxShadow::swap(QCBoxShadow &other)
Swaps this other with other. This operation is very fast and never fails.
float QCBoxShadow::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().
float QCBoxShadow::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().
[override virtual] QCBrush::BrushType QCBoxShadow::type() const
Reimplements: QCBrush::type() const.
Returns the type of brush, QCBrush::BrushType::BoxShadow.
QVariant QCBoxShadow::operator QVariant() const
Returns the box shadow as a QVariant.
bool QCBoxShadow::operator!=(const QCBoxShadow &shadow) const
Returns true if the box shadow is different from the given shadow; otherwise false.
See also operator==().
[noexcept] QCBoxShadow &QCBoxShadow::operator=(QCBoxShadow &&other)
Move-assigns other to this QCBoxShadow instance.
[noexcept] QCBoxShadow &QCBoxShadow::operator=(const QCBoxShadow &shadow)
Assigns the given shadow to this shadow and returns a reference to this box shadow.
bool QCBoxShadow::operator==(const QCBoxShadow &shadow) const
Returns true if the box shadow is equal to the given shadow; otherwise false.
See also operator!=().
Related Non-Members
QDataStream &operator<<(QDataStream &stream, const QCBoxShadow &shadow)
Writes the given shadow to the given stream and returns a reference to the stream.
See also Serializing Qt Data Types.
QDataStream &operator>>(QDataStream &stream, QCBoxShadow &shadow)
Reads the given shadow from the given stream and returns a reference to the stream.
See also Serializing Qt Data Types.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.