Home · All Classes · Modules

QBrush Class Reference
[QtGui module]

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

Methods

Special Methods


Detailed Description

A QColor may be used whenever a QBrush is expected.

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 appropiate 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. The gradient can only be set when constructing the brush, while the texture() can be set using the appropiate constructor or by using the setTexture() function. The texture() defines the pixmap used when the current style is Qt.TexturePattern.

Note that applying setTexture() makes style() == Qt.TexturePattern, independently 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:

Outlines 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} documentation.

See also Qt.BrushStyle, QPainter, and QColor.


Method Documentation

QBrush.__init__ (self)

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

QBrush.__init__ (self, Qt.BrushStyle bs)

Constructs a black brush with the given style.

See also setStyle().

QBrush.__init__ (self, QColor color, Qt.BrushStyle bs = Qt.SolidPattern)

Constructs a brush with the given color and style.

See also setColor() and setStyle().

QBrush.__init__ (self, Qt.GlobalColor color, Qt.BrushStyle bs = Qt.SolidPattern)

Constructs a brush with the given color and style.

See also setColor() and setStyle().

QBrush.__init__ (self, QColor color, 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() and setPixmap().

QBrush.__init__ (self, Qt.GlobalColor color, 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() and setPixmap().

QBrush.__init__ (self, 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.__init__ (self, QGradient gradient)

Constructs a copy of other.

QBrush.__init__ (self, QVariant)

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.__init__ (self, QBrush brush)

QColor QBrush.color (self)

Returns the brush color.

See also setColor().

QGradient QBrush.gradient (self)

Returns the gradient describing this brush.

bool QBrush.isOpaque (self)

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

QBrush.setColor (self, QColor color)

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.

See also color().

QBrush.setColor (self, Qt.GlobalColor acolor)

This is an overloaded member function, provided for convenience.

Sets the brush color to the given color.

QBrush.setStyle (self, Qt.BrushStyle)

Sets the brush style to style.

See also style().

QBrush.setTexture (self, 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().

Qt.BrushStyle QBrush.style (self)

Returns the brush style.

See also setStyle().

QPixmap QBrush.texture (self)

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

See also setTexture().

bool QBrush.__eq__ (self, QBrush b)

bool QBrush.__ne__ (self, QBrush b)


PyQt 4.0.1 for X11Copyright © Riverbank Computing Ltd and Trolltech AS 2006Qt 4.1.4