CopperSpice API  1.7.2
QBrush Class Reference

The QBrush class defines the fill pattern of shapes drawn by QPainter. More...

Public Methods

 QBrush ()
 
 QBrush (const QBrush &other)
 
 QBrush (const QColor &color, const QPixmap &pixmap)
 
 QBrush (const QColor &color, Qt::BrushStyle style=Qt::SolidPattern)
 
 QBrush (const QGradient &gradient)
 
 QBrush (const QImage &image)
 
 QBrush (const QPixmap &pixmap)
 
 QBrush (Qt::BrushStyle style)
 
 QBrush (Qt::GlobalColor color, const QPixmap &pixmap)
 
 QBrush (Qt::GlobalColor color, Qt::BrushStyle style=Qt::SolidPattern)
 
 ~QBrush ()
 
const QColorcolor () const
 
const QGradientgradient () const
 
bool isOpaque () const
 
const QMatrixmatrix () const
 
 operator QVariant () const
 
bool operator!= (const QBrush &brush) const
 
QBrush & operator= (const QBrush &other)
 
QBrush & operator= (QBrush &&other)
 
bool operator== (const QBrush &brush) const
 
void setColor (const QColor &color)
 
void setColor (Qt::GlobalColor color)
 
void setMatrix (const QMatrix &matrix)
 
void setStyle (Qt::BrushStyle style)
 
void setTexture (const QPixmap &pixmap)
 
void setTextureImage (const QImage &image)
 
void setTransform (const QTransform &transform)
 
Qt::BrushStyle style () const
 
void swap (QBrush &other)
 
QPixmap texture () const
 
QImage textureImage () const
 
QTransform transform () const
 

Friends

class QPainter
 
class QRasterPaintEngine
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &stream, const QBrush &brush)
 
QDataStreamoperator>> (QDataStream &stream, QBrush &brush)
 

Detailed Description

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.

The brush color() defines the color of the fill pattern. The color can either be one of the CopperSpice 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. CopperSpice provides three different gradients: QLinearGradient, QConicalGradient, and QRadialGradient - all of which inherit QGradient.

QRadialGradient gradient(50, 50, 50, 50, 50);

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:

  • The alpha component of the color() is 255.
  • Its texture() does not have an alpha channel and is not a QBitmap.
  • The colors in the gradient() all have an alpha component that is 255.

To specify the style and color of lines and outlines, use the QPainter's pen combined with Qt::PenStyle and Qt::GlobalColor:

QPainter painter(this);
painter.setBrush(Qt::cyan);
painter.setPen(Qt::darkCyan);
painter.drawRect(0, 0, 100,100);
painter.setBrush(Qt::NoBrush);
painter.setPen(Qt::darkGreen);
painter.drawRect(40, 40, 100, 100);

Note that, by default, QPainter renders the outline (using the currently set pen) when drawing shapes. Use painter.setPen(Qt::NoPen) to disable this behavior.

For more information about painting in general, see the Paint System.

See also
Qt::BrushStyle, QPainter, QColor

Constructor & Destructor Documentation

QBrush::QBrush ( )

Constructs a default black brush with the style Qt::NoBrush (i.e. this brush will not fill shapes).

QBrush::QBrush ( Qt::BrushStyle  style)

Constructs a black brush with the given style.

See also
setStyle()
QBrush::QBrush ( const QColor color,
Qt::BrushStyle  style = Qt::SolidPattern 
)

Constructs a brush with the given color and style.

See also
setColor(), setStyle()
QBrush::QBrush ( Qt::GlobalColor  color,
Qt::BrushStyle  style = Qt::SolidPattern 
)

Constructs a brush with the given color and style.

See also
setColor(), setStyle()
QBrush::QBrush ( const QColor 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.

See also
setColor(), setPixmap()
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.

See also
setColor(), setPixmap()
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.

See also
setTexture()
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.

See also
setTextureImage()
QBrush::QBrush ( const QBrush &  other)

Copy constructs a new QBrush from other.

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

QBrush::~QBrush ( )

Destroys the brush.

Method Documentation

const QColor & QBrush::color ( ) const
inline

Returns the brush color.

See also
setColor()
const QGradient * QBrush::gradient ( ) const

Returns the gradient describing this brush.

bool QBrush::isOpaque ( ) const

Returns true if the brush is fully opaque otherwise false. A brush is considered opaque if:

  • The alpha component of the color() is 255.
  • Its texture() does not have an alpha channel and is not a QBitmap.
  • The colors in the gradient() all have an alpha component that is 255.
  • It is an extended radial gradient.
const QMatrix & QBrush::matrix ( ) const
inline

Returns the current transformation matrix for the brush.

See also
setMatrix()
QBrush::operator QVariant ( ) const

Returns the brush as a QVariant.

bool QBrush::operator!= ( const QBrush &  brush) const
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.

See also
operator==()
QBrush & QBrush::operator= ( const QBrush &  other)

Copy assigns from other and returns a reference to this object.

QBrush & QBrush::operator= ( QBrush &&  other)
inline

Move assigns from other and returns a reference to this object.

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.

See also
operator!=()
void QBrush::setColor ( const QColor color)

Sets the brush color to the given color. 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.

See also
color()
void QBrush::setColor ( Qt::GlobalColor  color)
inline

Sets the brush color to the given color.

void QBrush::setMatrix ( const QMatrix 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.

See also
matrix()
void QBrush::setStyle ( Qt::BrushStyle  style)

Sets the brush style to style.

See also
style()
void QBrush::setTexture ( const QPixmap pixmap)

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

See also
texture()
void QBrush::setTextureImage ( const QImage image)

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.

See also
textureImage(), setTexture()
void QBrush::setTransform ( const QTransform transform)

Sets transform as an explicit transformation matrix on the current brush. The brush transformation matrix is merged with QPainter transformation matrix to produce the final result.

See also
transform()
Qt::BrushStyle QBrush::style ( ) const
inline

Returns the brush style.

See also
setStyle()
void QBrush::swap ( QBrush &  other)
inline

Swaps brush other with this brush. This operation is very fast and never fails.

QPixmap QBrush::texture ( ) const

Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.

See also
setTexture()
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.

See also
setTextureImage()
QTransform QBrush::transform ( ) const
inline

Returns the current transformation matrix for the brush.

See also
setTransform()

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream stream,
const QBrush &  brush 
)
related

Writes the given brush to the given stream and returns a reference to the stream.

See also
Refer to Serializing Data Types for additional information
QDataStream & operator>> ( QDataStream stream,
QBrush &  brush 
)
related

Reads the given brush from the given stream and returns a reference to the stream.

See also
Refer to Serializing Data Types for additional information