Table Of Contents

Previous topic

QLinearGradient

Next topic

QPaintDevice

QBrush

Inheritance diagram of QBrush

Synopsis

Functions

Detailed Description

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

A brush has a style, a color, a gradient and a texture.

The brush PySide.QtGui.QBrush.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 PySide.QtGui.QBrush.setStyle() function provides means for altering the style once the brush is constructed.

../../_images/brush-styles1.png

The brush PySide.QtGui.QBrush.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 PySide.QtGui.QColor . The currently set color can be retrieved and altered using the PySide.QtGui.QBrush.color() and PySide.QtGui.QBrush.setColor() functions, respectively.

The PySide.QtGui.QBrush.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 PySide.QtGui.QGradient as a constructor argument when creating the PySide.QtGui.QBrush . Qt provides three different gradients: PySide.QtGui.QLinearGradient , PySide.QtGui.QConicalGradient , and PySide.QtGui.QRadialGradient - all of which inherit PySide.QtGui.QGradient .

gradient = QRadialGradient gradient(50, 50, 50, 50, 50)
gradient.setColorAt(0, QColor.fromRgbF(0, 1, 0, 1))
gradient.setColorAt(1, QColor.fromRgbF(0, 0, 0, 0))

brush = QBrush(gradient)

The PySide.QtGui.QBrush.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 PySide.QtGui.QBrush.setTexture() .

Note that applying PySide.QtGui.QBrush.setTexture() makes PySide.QtGui.QBrush.style() == Qt.TexturePattern , regardless of previous style settings. Also, calling PySide.QtGui.QBrush.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 PySide.QtGui.QBitmap .

The PySide.QtGui.QBrush.isOpaque() function returns true if the brush is fully opaque otherwise false. A brush is considered opaque if:

../../_images/brush-outline.png

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

painter = QPainter(self)

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, PySide.QtGui.QPainter renders the outline (using the currently set pen) when drawing shapes. Use painter.setPen(Qt::NoPen) :attr:` <Qt.PenStyle>` to disable this behavior.

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

class PySide.QtGui.QBrush
class PySide.QtGui.QBrush(bs)
class PySide.QtGui.QBrush(color[, bs=Qt.SolidPattern])
class PySide.QtGui.QBrush(color, pixmap)
class PySide.QtGui.QBrush(brush)
class PySide.QtGui.QBrush(color[, bs=Qt.SolidPattern])
class PySide.QtGui.QBrush(color, pixmap)
class PySide.QtGui.QBrush(gradient)
class PySide.QtGui.QBrush(image)
class PySide.QtGui.QBrush(pixmap)
Parameters:

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

Constructs a copy of other .

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

PySide.QtGui.QBrush.setColor() setPixmap()

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

Constructs a brush with a black color and a texture set to the given image . The style is set to Qt.TexturePattern .

Constructs a brush with a black color and a texture set to the given pixmap . The style is set to Qt.TexturePattern .

PySide.QtGui.QBrush.color()
Return type:PySide.QtGui.QColor

Returns the brush color.

PySide.QtGui.QBrush.gradient()
Return type:PySide.QtGui.QGradient

Returns the gradient describing this brush.

PySide.QtGui.QBrush.init(color, bs)
Parameters:
PySide.QtGui.QBrush.isOpaque()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QBrush.matrix()
Return type:PySide.QtGui.QMatrix

Returns the current transformation matrix for the brush.

PySide.QtGui.QBrush.__ne__(b)
Parameters:bPySide.QtGui.QBrush
Return type:PySide.QtCore.bool

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

PySide.QtGui.QBrush.operator==()

PySide.QtGui.QBrush.__eq__(b)
Parameters:bPySide.QtGui.QBrush
Return type:PySide.QtCore.bool

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

PySide.QtGui.QBrush.operator!=()

PySide.QtGui.QBrush.setColor(color)
Parameters:colorPySide.QtGui.QColor

Sets the brush color to the given color .

Note that calling PySide.QtGui.QBrush.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 PySide.QtGui.QBitmap .

PySide.QtGui.QBrush.setColor(color)
Parameters:colorPySide.QtCore.Qt.GlobalColor
PySide.QtGui.QBrush.setMatrix(mat)
Parameters:matPySide.QtGui.QMatrix

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

PySide.QtGui.QBrush.setStyle(arg__1)
Parameters:arg__1PySide.QtCore.Qt.BrushStyle
PySide.QtGui.QBrush.setTexture(pixmap)
Parameters:pixmapPySide.QtGui.QPixmap

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

PySide.QtGui.QBrush.setTextureImage(image)
Parameters:imagePySide.QtGui.QImage

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 PySide.QtGui.QBrush.setTexture() with a PySide.QtGui.QBitmap . If you want to change the color of monochrome image brushes, either convert the image to PySide.QtGui.QBitmap with QBitmap::fromImage() and set the resulting PySide.QtGui.QBitmap as a texture, or change the entries in the color table for the image.

PySide.QtGui.QBrush.setTransform(arg__1)
Parameters:arg__1PySide.QtGui.QTransform

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

PySide.QtGui.QBrush.style()
Return type:PySide.QtCore.Qt.BrushStyle

Returns the brush style.

PySide.QtGui.QBrush.texture()
Return type:PySide.QtGui.QPixmap

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

PySide.QtGui.QBrush.textureImage()
Return type:PySide.QtGui.QImage

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

If the texture was set as a PySide.QtGui.QPixmap it will be converted to a PySide.QtGui.QImage .

PySide.QtGui.QBrush.transform()
Return type:PySide.QtGui.QTransform

Returns the current transformation matrix for the brush.