PySide6.QtCanvasPainter.QCanvasBoxShadow

class QCanvasBoxShadow

QCanvasBoxShadow is a brush for painting rectangle shadows / glows.

Details

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:

../../_images/examples_css_box_shadow.png

QCanvasBoxShadow :

../../_images/examples_qcpainter_box_shadow.png

Inheritance diagram of PySide6.QtCanvasPainter.QCanvasBoxShadow

Synopsis

Methods

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

__init__()

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.

__init__(rect[, radius=0.0f[, blur=0.0f[, color=QColorConstants.Black]]])
Parameters:
  • rectQRectF

  • radius – float

  • blur – float

  • colorQColor

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.

__init__(x, y, width, height[, radius=0.0f[, blur=0.0f[, color=QColorConstants.Black]]])
Parameters:
  • x – float

  • y – float

  • width – float

  • height – float

  • radius – float

  • blur – float

  • colorQColor

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.

blur()
Return type:

float

Returns the blur of shadow box.

See also

setBlur()

bottomLeftRadius()
Return type:

float

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.

bottomRightRadius()
Return type:

float

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.

boundingRect()
Return type:

QRectF

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

color()
Return type:

QColor

Returns the color of shadow box.

See also

setColor()

__ne__(rhs)
Parameters:

rhsQCanvasBoxShadow

Return type:

bool

__eq__(rhs)
Parameters:

rhsQCanvasBoxShadow

Return type:

bool

radius()
Return type:

float

Returns the radius of shadow box.

See also

setRadius()

rect()
Return type:

QRectF

Returns the rect area of shadow box.

See also

setRect()

setBlur(blur)
Parameters:

blur – float

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

See also

blur()

setBottomLeftRadius(radius)
Parameters:

radius – float

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.

setBottomRightRadius(radius)
Parameters:

radius – float

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.

setColor(color)
Parameters:

colorQColor

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

See also

color()

setRadius(radius)
Parameters:

radius – float

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

See also

radius()

setRect(rect)
Parameters:

rectQRectF

Sets the rect area of shadow box to rect.

setRect(x, y, width, height)
Parameters:
  • x – float

  • y – float

  • width – float

  • height – float

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

See also

rect()

setSpread(spread)
Parameters:

spread – float

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

See also

spread()

setTopLeftRadius(radius)
Parameters:

radius – float

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()

setTopRightRadius(radius)
Parameters:

radius – float

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()

spread()
Return type:

float

Returns the spread of shadow box.

See also

setSpread()

topLeftRadius()
Return type:

float

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.

topRightRadius()
Return type:

float

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.