Qt logo

QBrush Class Reference


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

#include <qbrush.h>

List of all member functions.

Public Members

Related Functions

(Note that these are not member functions.)

Detailed Description

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

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

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 lists the predefined colors.

Use the QPen class for specifying line/outline styles.

Example:

    QPainter painter;
    QBrush   brush( yellow );           // yellow solid pattern
    painter.begin( &anyPaintDevice );   // paint something
    painter.setBrush( brush );          // set the yellow brush
    painter.setPen( NoPen );            // do not draw outline
    painter.drawRect( 40,30, 200,100 ); // draw filled rectangle
    painter.setBrush( NoBrush );        // do not fill
    painter.setPen( black );            // set black pen, 0 pixel width
    painter.drawRect( 10,10, 30,20 );   // draw rectangle outline
    painter.end();                      // painting done

See the setStyle() function for a complete list of brush styles.

See also: QPainter, QPainter::setBrush() and QPainter::setBrushOrigin().

Examples: tictac/tictac.cpp drawdemo/drawdemo.cpp picture/picture.cpp


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.

See also: setStyle().

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

Constructs a brush with a specified color and style.

See also: setColor() and setStyle().

QBrush::QBrush ( const QColor & color, const QPixmap & pixmap )

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

The color will only have an effect for monochrome pixmaps, i.e. QPixmap::depth() == 1.

See also: setColor() and setPixmap().

QBrush::QBrush ( const QBrush & b )

Constructs a brush which is a shallow copy of b.

QBrush::~QBrush ()

Destroys the brush.

const QColor & QBrush::color () const

Returns the brush color.

See also: setColor().

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

See also: operator==().

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

Assigns b to this 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 pixmaps.

See also: operator!=().

QPixmap * QBrush::pixmap () const

Returns a pointer to the custom brush pattern.

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

See also: setPixmap().

void QBrush::setColor ( const QColor & c )

Sets the brush color to c.

See also: color() and setStyle().

Examples: picture/picture.cpp

void QBrush::setPixmap ( const QPixmap & pixmap )

Sets the brush pixmap. The style is set to CustomPattern.

The curren brush color will only have an effect for monochrome pixmaps, i.e. QPixmap::depth() == 1.

See also: pixmap() and color().

void QBrush::setStyle ( BrushStyle s )

Sets the brush style to s.

The brush styles are:

See also: style().

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 and returns a reference to the stream.

The serialization format is:

  1. The brush style (UINT8)
  2. The brush color (QColor)
  3. If style == CustomPattern: the brush pixmap (QPixmap)

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

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


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


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

It was generated from the following files:


Copyright © 1998 Troll TechTrademarks
Qt version 1.42