On this page

QCBoxGradient Class

QCBoxGradient is a brush for box gradient painting. More...

Header: #include <QCBoxGradient>
Inherits: QCGradient

Public Functions

QCBoxGradient()
QCBoxGradient(const QRectF &rect, float feather, float radius = 0.0f)
QCBoxGradient(float x, float y, float width, float height, float feather, float radius = 0.0f)
float feather() const
float radius() const
QRectF rect() const
void setFeather(float feather)
void setRadius(float radius)
void setRect(const QRectF &rect)
void setRect(float x, float y, float width, float height)

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:

QRectF rect(50, 50, 200, 100);
QCBoxGradient bg(rect, 20, 50);
bg.setColorAt(0.0, Qt::darkBlue);
bg.setColorAt(0.2, Qt::darkYellow);
bg.setColorAt(1.0, Qt::transparent);
painter.setFillStyle(bg);
painter.fillRect(rect);

Note: When QCBoxGradient is used to paint round rectangle, it is usually better to use QCPainter::rect() than QCPainter::roundRect() as the rounding comes from the brush rather than the path. This avoids creating extra vertices and thus performs better.

Member Function Documentation

QCBoxGradient::QCBoxGradient()

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

QCBoxGradient::QCBoxGradient(const QRectF &rect, float feather, float radius = 0.0f)

Constructs a box gradient. Position and size of gradient is rect. Gradient feather is feather. Gradient radius is radius. Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

QCBoxGradient::QCBoxGradient(float x, float y, float width, float height, float feather, float radius = 0.0f)

Constructs a box gradient. Position of gradient is ( x, y) and size ( width, height) Gradient feather is feather. Gradient radius is radius. Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

float QCBoxGradient::feather() const

Returns the feather of the box gradient.

See also setFeather().

float QCBoxGradient::radius() const

Returns the radius of the box gradient.

See also setRadius().

QRectF QCBoxGradient::rect() const

Returns the rectangle area of the box gradient.

See also setRect().

void QCBoxGradient::setFeather(float feather)

Sets the feather of box gradient to feather.

See also feather().

void QCBoxGradient::setRadius(float 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 QCBoxGradient::setRect(const QRectF &rect)

Sets the rectangle of box gradient to rect.

See also rect().

void QCBoxGradient::setRect(float x, float y, float width, float height)

Sets the rectangle of box gradient to position ( x, y) and size ( width, height).

© 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.