Skip to content

PythonQt.Qt.QBrush

QBrush

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

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 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. Gradient brushes are created by giving a QGradient as a constructor argument when creating the QBrush. Qt provides three different gradients: QLinearGradient, QConicalGradient, and 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);

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 using setTexture().

Note that applying setTexture() makes style() \=\= Qt::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 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:

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

Source: https://doc.qt.io/archives/qt-5.15/qbrush.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
color function (self) -> Any X.color() -> PythonQt.QtGui.QColor (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
gradient function (self) -> Any X.gradient() -> PythonQt.QtGui.QGradient (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
isOpaque function (self) -> bool X.isOpaque() -> bool (shared captured text)
matrix function (self) -> Any X.matrix() -> PythonQt.QtGui.QMatrix (shared captured text)
readFrom function (self, arg__1: Any) -> Any (shared captured text)
setColor function (self, color: Any) -> None Sets the brush color to the given color. (shared captured text)
setMatrix function (self, mat: Any) -> None (shared captured text)
setStyle function (self, arg__1: Any) -> None Sets the brush style to style. (shared captured text)
setTexture function (self, pixmap: Any) -> None Sets the brush pixmap to pixmap. (shared captured text)
setTextureImage function (self, image: Any) -> None Sets the brush image to image. (shared captured text)
setTransform function (self, arg__1: Any) -> None Sets matrix as an explicit transformation matrix on the current brush. (shared captured text)
style function (self) -> Any Returns the brush style. (shared captured text)
swap function (self, other: Any) -> None Swaps brush other with this brush. (shared captured text)
texture function (self) -> Any X.texture() -> PythonQt.QtGui.QPixmap (shared captured text)
textureImage function (self) -> Any X.textureImage() -> PythonQt.QtGui.QImage (shared captured text)
transform function (self) -> Any X.transform() -> PythonQt.QtGui.QTransform (shared captured text)
writeTo function (self, arg__1: Any) -> Any (shared captured text)