def
__eq__
(b)
def
__ne__
(b)
def
color
()
def
gradient
()
def
isOpaque
()
def
matrix
()
def
setColor
(color)
def
setColor
(color)
def
setMatrix
(mat)
def
setStyle
(arg__1)
def
setTexture
(pixmap)
def
setTextureImage
(image)
def
setTransform
(arg__1)
def
style
()
def
swap
(other)
def
texture
()
def
textureImage
()
def
transform
()
A brush has a style, a color, a gradient and a texture.
The brush
style()defines the fill pattern using theBrushStyleenum. The default brush style isNoBrush(depending on how you construct a brush). This style tells the painter to not fill shapes. The standard style for filling isSolidPattern. The style can be set when the brush is created using the appropriate constructor, and in addition thesetStyle()function provides means for altering the style once the brush is constructed.![]()
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 customQColor. The currently set color can be retrieved and altered using thecolor()andsetColor()functions, respectively.
gradient()defines the gradient fill used when the current style is eitherLinearGradientPattern,RadialGradientPatternorConicalGradientPattern. Gradient brushes are created by giving aQGradientas a constructor argument when creating theQBrush. Qt provides three different gradients:QLinearGradient,QConicalGradient,和QRadialGradient- all of which inheritQGradient.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 isTexturePattern. You can create a brush with a texture by providing the pixmap when the brush is created or by usingsetTexture().Note that applying
setTexture()makesstyle()==TexturePattern, regardless of previous style settings. Also, callingsetColor()will not make a difference if the style is a gradient. The same is the case if the style isTexturePatternstyle unless the current texture is aQBitmap.
isOpaque()function returnstrueif 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 aQBitmap.The colors in the
gradient()all have an alpha component that is 255.
![]()
To specify the style and color of lines and outlines, use the
QPainter‘spencombined withPenStyleandGlobalColor: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,
QPainterrenders the outline (using the currently set pen) when drawing shapes. Usepainter.setPen(Qt::NoPen):attr:` <Qt.PenStyle>` to disable this behavior.For more information about painting in general, see the 描绘系统 .
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)
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
.
另请参阅
构造笔刷采用给定
color
and
style
.
另请参阅
PySide2.QtGui.QBrush.
color
(
)
¶
Returns the brush color.
另请参阅
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
(
)
¶
注意
此函数被弃用。
使用
transform()
代替。
Returns the current transformation matrix for the brush.
另请参阅
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.
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.
另请参阅
PySide2.QtGui.QBrush.
setStyle
(
arg__1
)
¶
arg__1
–
BrushStyle
Sets the brush style to
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
).
另请参阅
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.
另请参阅
PySide2.QtGui.QBrush.
style
(
)
¶
BrushStyle
Returns the brush style.
另请参阅
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
(
)
¶
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
另请参阅
PySide2.QtGui.QBrush.
textureImage
(
)
¶
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
.
另请参阅
PySide2.QtGui.QBrush.
transform
(
)
¶
Returns the current transformation matrix for the brush.
另请参阅