PySide6.QtCanvasPainter.QCanvasBoxGradient¶
- class QCanvasBoxGradient¶
QCanvasBoxGradientis a brush for box gradient painting.Details
Box gradient interpolate colors between start and end points, creating a rounded rectangle shaped gradient. With the
setRadius()andsetFeather()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
QCanvasBoxGradientis used to paint round rectangle, it is usually better to userect()thanroundRect()as the rounding comes from the brush rather than the path. This avoids creating extra vertices and thus performs better.Synopsis¶
Methods¶
def
__init__()def
feather()def
radius()def
rect()def
setFeather()def
setRadius()def
setRect()
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 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).
- __init__(rect, feather[, radius=0.0f])
- Parameters:
rect –
QRectFfeather – float
radius – float
Constructs a box gradient. Position and size of gradient is
rect. Gradient feather isfeather. Gradient radius isradius. Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).- __init__(x, y, width, height, feather[, radius=0.0f])
- Parameters:
x – float
y – float
width – float
height – float
feather – float
radius – float
Constructs a box gradient. Position of gradient is (
x,y) and size (width,height) Gradient feather isfeather. Gradient radius isradius. Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).- feather()¶
- Return type:
float
Returns the feather of the box gradient.
See also
- radius()¶
- Return type:
float
Returns the radius of the box gradient.
See also
Returns the rectangle area of the box gradient.
See also
- setFeather(feather)¶
- Parameters:
feather – float
Sets the feather of box gradient to
feather.See also
- setRadius(radius)¶
- Parameters:
radius – float
Sets the radius of box gradient to
radius. The maximum radius is half of width or height ofrect(), depending on which one is smaller.See also
Sets the rectangle of box gradient to
rect.- setRect(x, y, width, height)
- Parameters:
x – float
y – float
width – float
height – float
Sets the rectangle of box gradient to position (
x,y) and size (width,height).See also