QBrush Class Reference


The QBrush class defines the fill pattern of shapes drawn using the QPainter. (details) (complete member list)

#include <qbrush.h>

Public Members

Related Functions

(Note that these are not member functions.)

Detailed Description

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

A brush has a style and a color. One of the brush styles is a custom pattern, which is defined by a QBitmap.

The brush style defines the fill pattern. The default brush style is NoBrush (depends on how you construct a brush). This style tells the painter to not fill shapes. The standard style for filling is called SolidPattern.

The brush color defines the color of the fill pattern. The QColor documentation contains a list of standard colors.

Use the QPen class for specifying line/outline styles.

Example of how to use a brush:

  QPainter painter;
  QBrush   brush( yellow );             // yellow solid pattern
  QPen     pen( red );                  // red solid line, 0 width
  painter.begin( &anyPaintDevice );     // paint widget, pixmap etc.
  painter.setBrush( brush );            // sets the yellow brush
  painter.setPen( pen );                // sets the red pen
  painter.drawRect( 40,30, 200,100 );   // draw 200x100 rect at (40,30)
  painter.brush().setStyle( NoBrush );  // do not fill
  painter.drawrect( 10,10, 30,20 );     // draw rectangle outline
  painter.end();                        // painting done

The setStyle() function has a list of brush styles.


Member Function Documentation

QBrush::QBrush ()

Constructs a default black brush with the style NoBrush (will not fill shapes).

QBrush::QBrush (BrushStyle style)

Constructs a black brush with the specified style.

QBrush::QBrush (const QColor &color, BrushStyle style=SolidPattern)

Constructs a brush with a specified color and style.

QBrush::QBrush (const QColor &color, const QBitmap &bitmap)

Constructs a brush with a specified color and a custom pattern.

QBrush::QBrush (const QBrush &b)

Constructs a brush which is a shallow copy of b.

QBrush::~QBrush ()

Destroys the brush.

QBitmap * QBrush::bitmap () const

Returns a pointer to the custom brush pattern.

A null pointer is returned if no custom brush pattern has been set.

See also: setBitmap().

QColor QBrush::color () const

Returns the brush color.

See also: setColor().

QBrush QBrush::copy () const

Returns a deep copy of the brush.

void QBrush::detach ()

Detaches from shared brush data to makes sure that this brush is the only one referring the data.

If multiple brushes share common data, this pen dereferences the data and gets a copy of the data. Nothing will be done if there is just a single reference.

bool QBrush::operator!= (const QBrush &b) const

Returns TRUE if the brush is different from b, or FALSE if the brushes are equal.

Two brushes are different if they have different styles, colors or bitmaps.

QBrush & QBrush::operator= (const QBrush &b)

Assigns a shallow copy of b to the brush and returns a reference to this brush.

bool QBrush::operator== (const QBrush &b) const

Returns TRUE if the brush is equal to b, or FALSE if the brushes are different.

Two brushes are equal if they have equal styles, colors and bitmaps.

BrushStyle QBrush::style () const

Returns the brush style.

See also: setStyle().


Related Functions

QDataStream & operator<< (QDataStream &s, const QBrush &b)

Writes a brush to the stream.

QDataStream & operator>> (QDataStream &s, QBrush &b)

Reads a brush from the stream.


This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 04:27, 1995/05/20 by the webmaster at Troll Tech