QBrush Class
The QBrush class defines the fill pattern of shapes drawn by QPainter. More…
| Header | #include <QBrush> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Gui) |
| Module | Nt GUI C++ Classes |
List of all members, including inherited members
Public Functions
| QBrush() | |
| QBrush(Qt::BrushStyle style) | |
| QBrush(const QColor &color, Qt::BrushStyle style = Qt::SolidPattern) | |
| QBrush(Qt::GlobalColor color, Qt::BrushStyle style = Qt::SolidPattern) | |
| QBrush(const QGradient &gradient) | |
| Qt::BrushStyle | style() const |
| void | setStyle(Qt::BrushStyle style) |
| const QColor & | color() const |
| void | setColor(const QColor &color) |
| void | setColor(Qt::GlobalColor color) |
| const QGradient * | gradient() const |
| QTransform | transform() const |
| void | setTransform(const QTransform &matrix) |
| bool | isOpaque() const |
Detailed Description
A brush has a color and a style. The default brush has the style Qt::NoBrush, which fills nothing.
QPainter painter(&image);
painter.setBrush(QBrush(Qt::blue));
painter.drawRect(10, 10, 40, 40);
See also QPen, QPainter and QColor.
Differences from Qt
The styles are Qt::NoBrush, Qt::SolidPattern and the gradient patterns, which a QBrush made from a QGradient has. There are no textures or hatch patterns. Gradients fill paths and shapes drawn with floating-point coordinates or a transformation; fillRect() with integer coordinates fills with the color of the first stop.
Member Function Documentation
QBrush::QBrush()
Constructs a brush with the style Qt::NoBrush and the color black.
QBrush::QBrush(Qt::BrushStyle style)
This is an overloaded function.
Constructs a black brush with the given style.
QBrush::QBrush(const QColor &color, Qt::BrushStyle style = Qt::SolidPattern)
This is an overloaded function.
Constructs a brush with the given color and style.
QBrush::QBrush(Qt::GlobalColor color, Qt::BrushStyle style = Qt::SolidPattern)
This is an overloaded function.
Constructs a brush with the given color and style.
QBrush::QBrush(const QGradient &gradient)
Constructs a brush that fills with gradient.
const QColor & QBrush::color() const
Returns the brush color.
See also setColor().
const QGradient * QBrush::gradient() const
Returns the gradient of the brush, or nullptr if it has none.
bool QBrush::isOpaque() const
Returns true if the brush paints every pixel opaquely; otherwise returns false.
void QBrush::setColor(const QColor &color)
Sets the brush color to color.
See also color().
void QBrush::setColor(Qt::GlobalColor color)
This is an overloaded function.
Sets the brush color to color.
void QBrush::setStyle(Qt::BrushStyle style)
Sets the brush style to style.
See also style().
void QBrush::setTransform(const QTransform &matrix)
Sets the transformation of the gradient of the brush to matrix.
Qt::BrushStyle QBrush::style() const
Returns the brush style.
See also setStyle().
QTransform QBrush::transform() const
Returns the transformation of the gradient of the brush.