![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtGui More...
#include <qbrush.h>
Public Types | |
using | DataPtr = std::unique_ptr< QBrushData, QBrushDataPointerDeleter > |
Public Member Functions | |
QBrush () | |
Constructs a default black brush with the style Qt::NoBrush (i.e. | |
QBrush (Qt::BrushStyle bs) | |
Constructs a black brush with the given style. | |
QBrush (const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern) | |
Constructs a brush with the given color and style. | |
QBrush (Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern) | |
Constructs a brush with the given color and style. | |
QBrush (const QColor &color, const QPixmap &pixmap) | |
Constructs a brush with the given color and the custom pattern stored in pixmap. | |
QBrush (Qt::GlobalColor color, const QPixmap &pixmap) | |
Constructs a brush with the given color and the custom pattern stored in pixmap. | |
QBrush (const QPixmap &pixmap) | |
Constructs a brush with a black color and a texture set to the given pixmap. | |
QBrush (const QImage &image) | |
Constructs a brush with a black color and a texture set to the given image. | |
QBrush (const QBrush &brush) | |
Constructs a copy of other. | |
QBrush (const QGradient &gradient) | |
Constructs a brush based on the given gradient. | |
~QBrush () | |
Destroys the brush. | |
QBrush & | operator= (const QBrush &brush) |
Assigns the given brush to this brush and returns a reference to this brush. | |
void | swap (QBrush &other) noexcept |
operator QVariant () const | |
Returns the brush as a QVariant. | |
Qt::BrushStyle | style () const |
Returns the brush style. | |
void | setStyle (Qt::BrushStyle) |
Sets the brush style to style. | |
QTransform | transform () const |
void | setTransform (const QTransform &) |
QPixmap | texture () const |
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set. | |
void | setTexture (const QPixmap &pixmap) |
Sets the brush pixmap to pixmap. | |
QImage | textureImage () const |
void | setTextureImage (const QImage &image) |
const QColor & | color () const |
Returns the brush color. | |
void | setColor (const QColor &color) |
Sets the brush color to the given color. | |
void | setColor (Qt::GlobalColor color) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the brush color to the given color. | |
const QGradient * | gradient () const |
Returns the gradient describing this brush. | |
bool | isOpaque () const |
Returns true if the brush is fully opaque otherwise false. | |
bool | operator== (const QBrush &b) const |
Returns true if the brush is equal to the given brush; otherwise returns false . | |
bool | operator!= (const QBrush &b) const |
Returns true if the brush is different from the given brush; otherwise returns false . | |
bool | isDetached () const |
DataPtr & | data_ptr () |
Friends | |
class | QRasterPaintEngine |
class | QRasterPaintEnginePrivate |
struct | QSpanData |
class | QPainter |
bool Q_GUI_EXPORT | qHasPixmapTexture (const QBrush &brush) |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &stream, const QBrush &brush) |
Writes the given brush to the given stream and returns a reference to the stream. | |
QDataStream & | operator>> (QDataStream &stream, QBrush &brush) |
Reads the given brush from the given stream and returns a reference to the stream. | |
\inmodule QtGui
The QBrush class defines the fill pattern of shapes drawn by QPainter.
A brush has a style, a color, a gradient and a texture.
The brush style() defines the fill pattern using the Qt::BrushStyle enum. The default brush style is Qt::NoBrush (depending on how you construct a brush). This style tells the painter to not fill shapes. The standard style for filling is Qt::SolidPattern. The style can be set when the brush is created using the appropriate constructor, and in addition the setStyle() function provides means for altering the style once the brush is constructed.
Brush Styles
The brush color() defines the color of the fill pattern. The color can either be one of Qt's predefined colors, Qt::GlobalColor, or any other custom QColor. The currently set color can be retrieved and altered using the color() and setColor() functions, respectively.
The gradient() defines the gradient fill used when the current style is either Qt::LinearGradientPattern, Qt::RadialGradientPattern or Qt::ConicalGradientPattern. Gradient brushes are created by giving a QGradient as a constructor argument when creating the QBrush. Qt provides three different gradients: QLinearGradient, QConicalGradient, and QRadialGradient
The texture() defines the pixmap used when the current style is Qt::TexturePattern. You can create a brush with a texture by providing the pixmap when the brush is created or by using setTexture().
Note that applying setTexture() makes style() == Qt::TexturePattern, regardless of previous style settings. Also, calling setColor() will not make a difference if the style is a gradient. The same is the case if the style is Qt::TexturePattern style unless the current texture is a QBitmap.
The isOpaque() function returns true
if the brush is fully opaque otherwise false. A brush is considered opaque if:
\list
\table 100% \row
To specify the style and color of lines and outlines, use the QPainter's \l {QPen}{pen} combined with Qt::PenStyle and Qt::GlobalColor:
Note that, by default, QPainter renders the outline (using the currently set pen) when drawing shapes. Use \l {Qt::NoPen}{painter.setPen(Qt::NoPen)}
to disable this behavior.
\endtable
For more information about painting in general, see the \l{Paint System}.
QBrush::QBrush | ( | ) |
Constructs a default black brush with the style Qt::NoBrush (i.e.
this brush will not fill shapes).
Definition at line 393 of file qbrush.cpp.
References Q_ASSERT.
QBrush::QBrush | ( | Qt::BrushStyle | style | ) |
Constructs a black brush with the given style.
Definition at line 433 of file qbrush.cpp.
QBrush::QBrush | ( | const QColor & | color, |
Qt::BrushStyle | style = Qt::SolidPattern |
||
) |
Constructs a brush with the given color and style.
Definition at line 444 of file qbrush.cpp.
References nullBrushInstance(), qbrush_check_type(), and style().
QBrush::QBrush | ( | Qt::GlobalColor | color, |
Qt::BrushStyle | style = Qt::SolidPattern |
||
) |
Constructs a brush with the given color and style.
Definition at line 461 of file qbrush.cpp.
Constructs a brush with the given color and the custom pattern stored in pixmap.
The style is set to Qt::TexturePattern. The color will only have an effect for QBitmaps.
Definition at line 476 of file qbrush.cpp.
References pixmap, setTexture(), and Qt::TexturePattern.
QBrush::QBrush | ( | Qt::GlobalColor | color, |
const QPixmap & | pixmap | ||
) |
Constructs a brush with the given color and the custom pattern stored in pixmap.
The style is set to Qt::TexturePattern. The color will only have an effect for QBitmaps.
Definition at line 492 of file qbrush.cpp.
References pixmap, setTexture(), and Qt::TexturePattern.
QBrush::QBrush | ( | const QPixmap & | pixmap | ) |
Constructs a brush with a black color and a texture set to the given pixmap.
The style is set to Qt::TexturePattern.
Definition at line 407 of file qbrush.cpp.
References Qt::black, pixmap, setTexture(), and Qt::TexturePattern.
QBrush::QBrush | ( | const QImage & | image | ) |
Constructs a brush with a black color and a texture set to the given image.
The style is set to Qt::TexturePattern.
Definition at line 421 of file qbrush.cpp.
References Qt::black, setTextureImage(), and Qt::TexturePattern.
QBrush::QBrush | ( | const QBrush & | brush | ) |
Constructs a copy of other.
Definition at line 502 of file qbrush.cpp.
QBrush::QBrush | ( | const QGradient & | gradient | ) |
Constructs a brush based on the given gradient.
The brush style is set to the corresponding gradient style (either Qt::LinearGradientPattern, Qt::RadialGradientPattern or Qt::ConicalGradientPattern).
Definition at line 515 of file qbrush.cpp.
References Qt::ConicalGradientPattern, QGradientBrushData::gradient, gradient(), Qt::LinearGradientPattern, QGradient::NoGradient, nullBrushInstance(), Q_UNLIKELY, Qt::RadialGradientPattern, and QGradient::type().
QBrush::~QBrush | ( | ) |
Destroys the brush.
Definition at line 538 of file qbrush.cpp.
|
inline |
Returns the brush color.
Definition at line 121 of file qbrush.h.
Referenced by QQuickTextNodeEngine::addBorder(), QQuickTextNodeEngine::addFrameDecorations(), QQuickTextNodeEngine::addText(), QQuickTextNodeEngine::addTextBlock(), QTextMarkdownImporter::cbEnterSpan(), QTextMarkdownImporter::cbLeaveSpan(), QPen::color(), QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(), QQC2_NAMESPACE::QMacStyle::drawComplexControl(), QQC2::QCommonStyle::drawComplexControl(), QQC2::QWindowsStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QAndroidStyle::AndroidControl::drawControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QQC2::QWindowsStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QQC2::QWindowsXPStyle::drawControl(), QQC2::QStyleHelper::drawDial(), QStyle::drawItemText(), QQC2::QStyle::drawItemText(), QQC2_NAMESPACE::QMacStyle::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QLCDNumberPrivate::drawSegment(), QWin32PrintEngine::drawTextItem(), QTextEditPrivate::paint(), QCommandLinkButton::paintEvent(), QLineEdit::paintEvent(), QWizardHeader::paintEvent(), QWindowsVistaStyle::polish(), QSvgPaintEngine::qbrushToSvg(), qDrawShadeLine(), QQC2::qDrawShadeLine(), qDrawShadePanel(), QQC2::qDrawShadePanel(), qDrawShadeRect(), QQC2::qDrawShadeRect(), qDrawWinButton(), QQC2::qDrawWinButton(), qDrawWinPanel(), QQC2::qDrawWinPanel(), qt_ensure_default_accent_color(), qt_mac_createSystemPalette(), QWizardPrivate::recreateLayout(), QPainter::setBackground(), QPalette::setColorGroup(), QTextOdfWriter::tableCellStyleElement(), QWindowsDirect2DPaintEnginePrivate::to_d2d_brush(), toolTipPalette(), QPicturePaintEngine::updateBackground(), QOpenGL2PaintEngineExPrivate::updateBrushUniforms(), QPainterPrivate::updateEmulationSpecifier(), and QWizardPrivate::updatePalette().
const QGradient * QBrush::gradient | ( | ) | const |
Returns the gradient describing this brush.
Definition at line 791 of file qbrush.cpp.
References Qt::ConicalGradientPattern, gradient(), Qt::LinearGradientPattern, and Qt::RadialGradientPattern.
Referenced by QBrush(), gradient(), isOpaque(), QSvgPaintEngine::qbrushToSvg(), QWindowsDirect2DPaintEnginePrivate::to_d2d_brush(), QOpenGL2PaintEngineExPrivate::updateBrushTexture(), and QOpenGL2PaintEngineExPrivate::updateBrushUniforms().
bool QBrush::isOpaque | ( | ) | const |
Returns true
if the brush is fully opaque otherwise false.
A brush is considered opaque if:
\list
Definition at line 830 of file qbrush.cpp.
References QList< T >::at(), Qt::ConicalGradientPattern, gradient(), QImage::hasAlphaChannel(), QPixmap::hasAlphaChannel(), i, QPixmap::isQBitmap(), Qt::LinearGradientPattern, qHasPixmapTexture, qt_isExtendedRadialGradient(), Qt::RadialGradientPattern, QList< T >::size(), Qt::SolidPattern, QGradient::stops(), texture(), textureImage(), and Qt::TexturePattern.
Referenced by QPaintEngineEx::drawPoints(), QPaintEngineEx::drawPoints(), QOpenGL2PaintEngineExPrivate::fill(), QWidgetPrivate::init(), QWidgetPrivate::paintBackground(), QGraphicsView::paintEvent(), QOpenGL2PaintEngineExPrivate::stroke(), QPainterPrivate::updateEmulationSpecifier(), QWidgetPrivate::updateIsOpaque(), QPdfEngine::updateState(), and QAlphaPaintEngine::updateState().
QBrush::operator QVariant | ( | ) | const |
Returns the brush as a QVariant.
Definition at line 636 of file qbrush.cpp.
References QVariant::fromValue().
|
inline |
Returns true
if the brush is different from the given brush; otherwise returns false
.
Two brushes are different if they have different styles, colors or transforms or different pixmaps or gradients depending on the style.
Definition at line 75 of file qbrush.h.
References operator==().
Assigns the given brush to this brush and returns a reference to this brush.
Move-assigns other to this QBrush instance.
Definition at line 607 of file qbrush.cpp.
bool QBrush::operator== | ( | const QBrush & | brush | ) | const |
Returns true
if the brush is equal to the given brush; otherwise returns false
.
Two brushes are equal if they have equal styles, colors and transforms and equal pixmaps or gradients depending on the style.
Definition at line 898 of file qbrush.cpp.
References QPixmap::cacheKey(), QPlatformPixmap::classId(), Qt::ConicalGradientPattern, d1, d2, QPixmap::handle(), Qt::LinearGradientPattern, qHasPixmapTexture, Qt::RadialGradientPattern, QPlatformPixmap::RasterClass, and Qt::TexturePattern.
Sets the brush color to the given color.
Note that calling setColor() will not make a difference if the style is a gradient. The same is the case if the style is Qt::TexturePattern style unless the current texture is a QBitmap.
Definition at line 687 of file qbrush.cpp.
Referenced by qt_mac_toQBrush(), and setColor().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the brush color to the given color.
Definition at line 94 of file qbrush.h.
References setColor().
void QBrush::setStyle | ( | Qt::BrushStyle | style | ) |
Sets the brush style to style.
Definition at line 655 of file qbrush.cpp.
References qbrush_check_type(), and style().
Referenced by qt_mac_toQBrush().
Sets the brush pixmap to pixmap.
The style is set to Qt::TexturePattern.
The current brush color will only have an effect for monochrome pixmaps, i.e. for QPixmap::depth() == 1 (\l {QBitmap}{QBitmaps}).
Definition at line 728 of file qbrush.cpp.
References Qt::NoBrush, pixmap, QTexturedBrushData::setPixmap(), and Qt::TexturePattern.
Referenced by QBrush(), QBrush(), and QBrush().
Sets the brush image to image. The style is set to Qt::TexturePattern.
Note the current brush color will not have any affect on monochrome images, as opposed to calling setTexture() with a QBitmap. If you want to change the color of monochrome image brushes, either convert the image to QBitmap with QBitmap::fromImage()
and set the resulting QBitmap as a texture, or change the entries in the color table for the image.
Definition at line 776 of file qbrush.cpp.
References Qt::NoBrush, QTexturedBrushData::setImage(), and Qt::TexturePattern.
Referenced by QBrush().
void QBrush::setTransform | ( | const QTransform & | matrix | ) |
Sets matrix as an explicit transformation matrix on the current brush. The brush transformation matrix is merged with QPainter transformation matrix to produce the final result.
Definition at line 867 of file qbrush.cpp.
|
inline |
Returns the brush style.
Definition at line 120 of file qbrush.h.
Referenced by QBrush(), QQuickTextNodeEngine::addFrameDecorations(), QQuickTextNodeEngine::addText(), QQuickTextNodeEngine::addTextBlock(), QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(), QQC2::QWindowsStyle::drawControl(), QTextDocumentLayoutPrivate::drawTableCell(), QWin32PrintEngine::drawTextItem(), QWidgetPrivate::drawWidget(), QOpenGL2PaintEngineExPrivate::fill(), QPainter::fillRect(), QPainter::fillRect(), QWidgetPrivate::init(), QPen::isSolid(), QOpenGL2PaintEngineExPrivate::prepareForDraw(), QSvgPaintEngine::qbrushToSvg(), QPainter::setBackground(), QOpenGL2PaintEngineExPrivate::setBrush(), QPainter::setPen(), setPenAndDrawBackground(), setStyle(), QSvgNode::strokeWidth(), QWindowsDirect2DPaintEnginePrivate::to_d2d_brush(), QPicturePaintEngine::updateBackground(), QOpenGL2PaintEngineExPrivate::updateBrushTexture(), QOpenGL2PaintEngineExPrivate::updateBrushUniforms(), QPainterPrivate::updateEmulationSpecifier(), QWidgetPrivate::updateIsOpaque(), QPdfEngine::updateState(), and QAlphaPaintEngine::updateState().
QPixmap QBrush::texture | ( | ) | const |
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
Definition at line 711 of file qbrush.cpp.
References Qt::TexturePattern.
Referenced by QQC2::QWindowsStyle::drawControl(), QWidgetPrivate::drawWidget(), isOpaque(), QWindowsDirect2DPaintEnginePrivate::to_d2d_brush(), QOpenGL2PaintEngineExPrivate::updateBrushUniforms(), and QPainterPrivate::updateEmulationSpecifier().
QImage QBrush::textureImage | ( | ) | const |
Returns the custom brush pattern, or a null image if no custom brush pattern has been set.
If the texture was set as a QPixmap it will be converted to a QImage.
Definition at line 752 of file qbrush.cpp.
References Qt::TexturePattern.
Referenced by QQC2::QWindowsStyle::drawControl(), isOpaque(), QOpenGL2PaintEngineExPrivate::updateBrushTexture(), and QPainterPrivate::updateEmulationSpecifier().
|
inline |
Returns the current transformation matrix for the brush.
Definition at line 122 of file qbrush.h.
Referenced by QOpenGL2PaintEngineExPrivate::setBrush(), QWindowsDirect2DPaintEnginePrivate::to_d2d_brush(), QOpenGL2PaintEngineExPrivate::updateBrushUniforms(), and QRasterPaintEngine::updatePen().
|
related |
Writes the given brush to the given stream and returns a reference to the stream.
Definition at line 998 of file qbrush.cpp.
References QList< T >::at(), Qt::ConicalGradientPattern, QGradient::coordinateMode(), i, QGradient::interpolationMode(), QGradient::LinearGradient, Qt::LinearGradientPattern, Qt::NoBrush, QGradient::ObjectBoundingMode, QGradient::ObjectMode, QDataStream::Qt_4_0, QDataStream::Qt_4_3, QDataStream::Qt_4_5, QDataStream::Qt_5_12, QDataStream::Qt_5_5, QDataStream::Qt_6_0, QGradient::RadialGradient, Qt::RadialGradientPattern, QList< T >::size(), QGradient::spread(), QGradient::stops(), Qt::TexturePattern, and QGradient::type().
|
related |
Reads the given brush from the given stream and returns a reference to the stream.
Definition at line 1074 of file qbrush.cpp.
References QGradient::ColorInterpolation, Qt::ConicalGradientPattern, i, QGradient::LinearGradient, Qt::LinearGradientPattern, QGradient::LogicalMode, p1, p2, QGradient::PadSpread, QDataStream::Qt_4_3, QDataStream::Qt_4_5, QDataStream::Qt_5_5, QDataStream::Qt_6_0, QGradient::RadialGradient, Qt::RadialGradientPattern, QList< T >::reserve(), QGradient::setCoordinateMode(), QRadialGradient::setFocalRadius(), QGradient::setInterpolationMode(), QGradient::setSpread(), QGradient::setStops(), and Qt::TexturePattern.
|
friend |
Definition at line 202 of file qbrush.cpp.
Referenced by isOpaque(), and operator==().
|
friend |
|
friend |