PySide6.QtGui.QBrush¶
- class QBrush¶
The
QBrush
class defines the fill pattern of shapes drawn byQPainter
. More…Synopsis¶
Methods¶
def
__init__()
def
color()
def
gradient()
def
isOpaque()
def
__ne__()
def
__eq__()
def
setColor()
def
setStyle()
def
setTexture()
def
setTransform()
def
style()
def
swap()
def
texture()
def
textureImage()
def
transform()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 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, Qt::GlobalColor, or any other customQColor
. The currently set color can be retrieved and altered using thecolor()
andsetColor()
functions, respectively.The
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 aQGradient
as a constructor argument when creating theQBrush
. Qt provides three different gradients:QLinearGradient
,QConicalGradient
, andQRadialGradient
- all of which inheritQGradient
.gradient = QRadialGradient(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
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 usingsetTexture()
.Note that applying
setTexture()
makesstyle()
== Qt::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 is Qt::TexturePattern style unless the current texture is aQBitmap
.The
isOpaque()
function returnstrue
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 aQBitmap
.The colors in the
gradient()
all have an alpha component that is 255.
Outlines
To specify the style and color of lines and outlines, use the
QPainter
‘spen
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,
QPainter
renders the outline (using the currently set pen) when drawing shapes. Usepainter.setPen(Qt::NoPen)
to disable this behavior.For more information about painting in general, see the Paint System .
- __init__()¶
Constructs a default black brush with the style Qt::NoBrush (i.e. this brush will not fill shapes).
- __init__(bs)
- Parameters:
bs –
BrushStyle
Constructs a black brush with the given
style
.See also
- __init__(brush)
- Parameters:
brush –
QBrush
Constructs a copy of
other
.- __init__(gradient)
- Parameters:
gradient –
QGradient
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).
- __init__(image)
- Parameters:
image –
QImage
Constructs a brush with a black color and a texture set to the given
image
. The style is set to Qt::TexturePattern.See also
- __init__(pixmap)
- Parameters:
pixmap –
QPixmap
Constructs a brush with a black color and a texture set to the given
pixmap
. The style is set to Qt::TexturePattern.See also
- __init__(color[, bs=Qt.SolidPattern])
- Parameters:
color –
GlobalColor
bs –
BrushStyle
Constructs a brush with the given
color
andstyle
.See also
- __init__(color, pixmap)
- Parameters:
color –
GlobalColor
pixmap –
QPixmap
Constructs a brush with the given
color
and the custom pattern stored inpixmap
.The style is set to Qt::TexturePattern. The color will only have an effect for QBitmaps.
See also
- __init__(color[, bs=Qt.SolidPattern])
- Parameters:
color –
QColor
bs –
BrushStyle
Constructs a brush with the given
color
andstyle
.See also
Constructs a brush with the given
color
and the custom pattern stored inpixmap
.The style is set to Qt::TexturePattern. The color will only have an effect for QBitmaps.
See also
Returns the brush color.
See also
Returns the gradient describing this brush.
- isOpaque()¶
- Return type:
bool
Returns
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 aQBitmap
.The colors in the
gradient()
all have an alpha component that is 255.It is an extended radial gradient.
Returns
true
if the brush is different from the givenbrush
; otherwise returnsfalse
.Two brushes are different if they have different styles, colors or transforms or different pixmaps or gradients depending on the style.
See also
operator==()
Returns
true
if the brush is equal to the givenbrush
; otherwise returnsfalse
.Two brushes are equal if they have equal styles, colors and transforms and equal pixmaps or gradients depending on the style.
See also
operator!=()
- setColor(color)¶
- Parameters:
color –
GlobalColor
This is an overloaded function.
Sets the brush color to the given
color
.- setColor(color)
- Parameters:
color –
QColor
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
- setStyle(arg__1)¶
- Parameters:
arg__1 –
BrushStyle
Sets the brush style to
style
.See also
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
depth()
== 1 (QBitmaps
).See also
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
setTexture()
with aQBitmap
. If you want to change the color of monochrome image brushes, either convert the image toQBitmap
withQBitmap::fromImage()
and set the resultingQBitmap
as a texture, or change the entries in the color table for the image.See also
- setTransform(arg__1)¶
- Parameters:
arg__1 –
QTransform
Sets
matrix
as an explicit transformation matrix on the current brush. The brush transformation matrix is merged withQPainter
transformation matrix to produce the final result.See also
- style()¶
- Return type:
Returns the brush style.
See also
Swaps brush
other
with this brush. This operation is very fast and never fails.Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
See also
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 aQImage
.See also
- transform()¶
- Return type:
Returns the current transformation matrix for the brush.
See also