内容表

上一话题

QBitmap

下一话题

QClipboard

QBrush

QBrush class defines the fill pattern of shapes drawn by QPainter . 更多

Inheritance diagram of PySide2.QtGui.QBrush

概要

函数

详细描述

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

The brush style() defines the fill pattern using the BrushStyle enum. The default brush style is NoBrush (depending on how you construct a brush). This style tells the painter to not fill shapes. The standard style for filling is 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.

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

The brush color() defines the color of the fill pattern. The color can either be one of Qt’s predefined colors, GlobalColor , or any other custom QColor . The currently set color can be retrieved and altered using the color() and setColor() functions, respectively.

gradient() defines the gradient fill used when the current style is either LinearGradientPattern , RadialGradientPattern or ConicalGradientPattern . Gradient brushes are created by giving a QGradient as a constructor argument when creating the QBrush . Qt provides three different gradients: QLinearGradient , QConicalGradient ,和 QRadialGradient - all of which inherit QGradient .

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));
QBrush brush(gradient);
											

texture() defines the pixmap used when the current style is 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() == 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 TexturePattern style unless the current texture is a QBitmap .

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

brush-outline1

To specify the style and color of lines and outlines, use the QPainter ‘s pen combined with PenStyle and 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, 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 描绘系统 .

另请参阅

BrushStyle QPainter QColor

class QBrush

QBrush(bs)

QBrush(color[, bs=Qt.SolidPattern])

QBrush(color, pixmap)

QBrush(brush)

QBrush(color[, bs=Qt.SolidPattern])

QBrush(color, pixmap)

QBrush(gradient)

QBrush(image)

QBrush(pixmap)

param image

QImage

param bs

BrushStyle

param brush

QBrush

param color

GlobalColor

param gradient

QGradient

param pixmap

QPixmap

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

Constructs a black brush with the given style .

另请参阅

setStyle()

构造笔刷采用给定 color and style .

PySide2.QtGui.QBrush. color ( )
返回类型

QColor

Returns the brush color.

另请参阅

setColor()

PySide2.QtGui.QBrush. gradient ( )
返回类型

QGradient

Returns the gradient describing this brush.

PySide2.QtGui.QBrush. isOpaque ( )
返回类型

bool

返回 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.

PySide2.QtGui.QBrush. matrix ( )
返回类型

QMatrix

注意

此函数被弃用。

使用 transform() 代替。

Returns the current transformation matrix for the brush.

另请参阅

setMatrix()

PySide2.QtGui.QBrush. __ne__ ( b )
参数

b QBrush

返回类型

bool

返回 true if the brush is different from the given brush ;否则返回 false .

Two brushes are different if they have different styles, colors or transforms or different pixmaps or gradients depending on the style.

另请参阅

operator==()

PySide2.QtGui.QBrush. __eq__ ( b )
参数

b QBrush

返回类型

bool

返回 true if the brush is equal to the given brush ;否则返回 false .

Two brushes are equal if they have equal styles, colors and transforms and equal pixmaps or gradients depending on the style.

另请参阅

operator!=()

PySide2.QtGui.QBrush. setColor ( color )
参数

color GlobalColor

这是重载函数。

Sets the brush color to the given color .

PySide2.QtGui.QBrush. setColor ( color )
参数

color QColor

PySide2.QtGui.QBrush. setMatrix ( mat )
参数

mat QMatrix

注意

此函数被弃用。

使用 setTransform() 代替。

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.

另请参阅

matrix()

PySide2.QtGui.QBrush. setStyle ( arg__1 )
参数

arg__1 BrushStyle

Sets the brush style to style .

另请参阅

style()

PySide2.QtGui.QBrush. setTexture ( pixmap )
参数

pixmap QPixmap

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

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

另请参阅

texture()

PySide2.QtGui.QBrush. setTextureImage ( image )
参数

image QImage

Sets the brush image to image . The style is set to TexturePattern .

Note the current brush color will not have any affect on monochrome images, as opposed to calling setTexture() 采用 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.

PySide2.QtGui.QBrush. setTransform ( arg__1 )
参数

arg__1 QTransform

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.

另请参阅

transform()

PySide2.QtGui.QBrush. style ( )
返回类型

BrushStyle

Returns the brush style.

另请参阅

setStyle()

PySide2.QtGui.QBrush. swap ( other )
参数

other QBrush

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

PySide2.QtGui.QBrush. texture ( )
返回类型

QPixmap

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

另请参阅

setTexture()

PySide2.QtGui.QBrush. textureImage ( )
返回类型

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 QPixmap it will be converted to a QImage .

另请参阅

setTextureImage()

PySide2.QtGui.QBrush. transform ( )
返回类型

QTransform

Returns the current transformation matrix for the brush.

另请参阅

setTransform()