#[repr(C)]pub struct QBrush { /* private fields */ }
Expand description
The QBrush class defines the fill pattern of shapes drawn by QPainter.
C++ class: QBrush
.
The QBrush class defines the fill pattern of shapes drawn by QPainter.
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.
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.
To specify the style and color of lines and outlines, use the QPainter's pen combined with Qt::PenStyle and Qt::GlobalColor:
Note that, by default, QPainter renders the outline (using the currently set pen) when drawing shapes. Use |
For more information about painting in general, see the Paint System.
Implementations§
source§impl QBrush
impl QBrush
sourcepub unsafe fn color(&self) -> Ref<QColor>
pub unsafe fn color(&self) -> Ref<QColor>
Returns the brush color.
Calls C++ function: const QColor& QBrush::color() const
.
Returns the brush color.
See also setColor().
sourcepub unsafe fn copy_from(&self, brush: impl CastInto<Ref<QBrush>>) -> Ref<QBrush>
pub unsafe fn copy_from(&self, brush: impl CastInto<Ref<QBrush>>) -> Ref<QBrush>
Assigns the given brush to this brush and returns a reference to this brush.
Calls C++ function: QBrush& QBrush::operator=(const QBrush& brush)
.
Assigns the given brush to this brush and returns a reference to this brush.
sourcepub unsafe fn gradient(&self) -> Ptr<QGradient>
pub unsafe fn gradient(&self) -> Ptr<QGradient>
Returns the gradient describing this brush.
Calls C++ function: const QGradient* QBrush::gradient() const
.
Returns the gradient describing this brush.
sourcepub unsafe fn is_detached(&self) -> bool
pub unsafe fn is_detached(&self) -> bool
Calls C++ function: bool QBrush::isDetached() const
.
sourcepub unsafe fn is_opaque(&self) -> bool
pub unsafe fn is_opaque(&self) -> bool
Returns true
if the brush is fully opaque otherwise false. A brush is considered opaque if:
Calls C++ function: bool QBrush::isOpaque() const
.
Returns true
if the brush is fully opaque otherwise false. A brush is considered opaque if:
sourcepub unsafe fn matrix(&self) -> Ref<QMatrix>
pub unsafe fn matrix(&self) -> Ref<QMatrix>
Returns the current transformation matrix for the brush.
Calls C++ function: const QMatrix& QBrush::matrix() const
.
Returns the current transformation matrix for the brush.
This function was introduced in Qt 4.2.
See also setMatrix().
sourcepub unsafe fn new() -> CppBox<QBrush>
pub unsafe fn new() -> CppBox<QBrush>
Constructs a default black brush with the style Qt::NoBrush (i.e. this brush will not fill shapes).
Calls C++ function: [constructor] void QBrush::QBrush()
.
Constructs a default black brush with the style Qt::NoBrush (i.e. this brush will not fill shapes).
sourcepub unsafe fn from_brush_style(bs: BrushStyle) -> CppBox<QBrush>
pub unsafe fn from_brush_style(bs: BrushStyle) -> CppBox<QBrush>
Constructs a black brush with the given style.
Calls C++ function: [constructor] void QBrush::QBrush(Qt::BrushStyle bs)
.
Constructs a black brush with the given style.
See also setStyle().
sourcepub unsafe fn from_q_color_brush_style(
color: impl CastInto<Ref<QColor>>,
bs: BrushStyle
) -> CppBox<QBrush>
pub unsafe fn from_q_color_brush_style( color: impl CastInto<Ref<QColor>>, bs: BrushStyle ) -> CppBox<QBrush>
Constructs a brush with the given color and style.
Calls C++ function: [constructor] void QBrush::QBrush(const QColor& color, Qt::BrushStyle bs = …)
.
sourcepub unsafe fn from_global_color_brush_style(
color: GlobalColor,
bs: BrushStyle
) -> CppBox<QBrush>
pub unsafe fn from_global_color_brush_style( color: GlobalColor, bs: BrushStyle ) -> CppBox<QBrush>
Constructs a brush with the given color and style.
Calls C++ function: [constructor] void QBrush::QBrush(Qt::GlobalColor color, Qt::BrushStyle bs = …)
.
sourcepub unsafe fn from_q_color_q_pixmap(
color: impl CastInto<Ref<QColor>>,
pixmap: impl CastInto<Ref<QPixmap>>
) -> CppBox<QBrush>
pub unsafe fn from_q_color_q_pixmap( color: impl CastInto<Ref<QColor>>, pixmap: impl CastInto<Ref<QPixmap>> ) -> CppBox<QBrush>
Constructs a brush with the given color and the custom pattern stored in pixmap.
Calls C++ function: [constructor] void QBrush::QBrush(const QColor& color, const QPixmap& pixmap)
.
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 setColor() and setTexture().
sourcepub unsafe fn from_global_color_q_pixmap(
color: GlobalColor,
pixmap: impl CastInto<Ref<QPixmap>>
) -> CppBox<QBrush>
pub unsafe fn from_global_color_q_pixmap( color: GlobalColor, pixmap: impl CastInto<Ref<QPixmap>> ) -> CppBox<QBrush>
Constructs a brush with the given color and the custom pattern stored in pixmap.
Calls C++ function: [constructor] void QBrush::QBrush(Qt::GlobalColor color, const QPixmap& pixmap)
.
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 setColor() and setTexture().
sourcepub unsafe fn from_q_pixmap(
pixmap: impl CastInto<Ref<QPixmap>>
) -> CppBox<QBrush>
pub unsafe fn from_q_pixmap( pixmap: impl CastInto<Ref<QPixmap>> ) -> CppBox<QBrush>
Constructs a brush with a black color and a texture set to the given pixmap. The style is set to Qt::TexturePattern.
Calls C++ function: [constructor] void QBrush::QBrush(const QPixmap& pixmap)
.
Constructs a brush with a black color and a texture set to the given pixmap. The style is set to Qt::TexturePattern.
See also setTexture().
sourcepub unsafe fn from_q_image(image: impl CastInto<Ref<QImage>>) -> CppBox<QBrush>
pub unsafe fn from_q_image(image: impl CastInto<Ref<QImage>>) -> CppBox<QBrush>
Constructs a brush with a black color and a texture set to the given image. The style is set to Qt::TexturePattern.
Calls C++ function: [constructor] void QBrush::QBrush(const QImage& image)
.
Constructs a brush with a black color and a texture set to the given image. The style is set to Qt::TexturePattern.
See also setTextureImage().
sourcepub unsafe fn from_q_gradient(
gradient: impl CastInto<Ref<QGradient>>
) -> CppBox<QBrush>
pub unsafe fn from_q_gradient( gradient: impl CastInto<Ref<QGradient>> ) -> CppBox<QBrush>
Constructs a brush based on the given gradient.
Calls C++ function: [constructor] void QBrush::QBrush(const QGradient& gradient)
.
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).
sourcepub unsafe fn from_q_color(color: impl CastInto<Ref<QColor>>) -> CppBox<QBrush>
pub unsafe fn from_q_color(color: impl CastInto<Ref<QColor>>) -> CppBox<QBrush>
Constructs a brush with the given color and style.
Calls C++ function: [constructor] void QBrush::QBrush(const QColor& color)
.
sourcepub unsafe fn from_global_color(color: GlobalColor) -> CppBox<QBrush>
pub unsafe fn from_global_color(color: GlobalColor) -> CppBox<QBrush>
Constructs a brush with the given color and style.
Calls C++ function: [constructor] void QBrush::QBrush(Qt::GlobalColor color)
.
sourcepub unsafe fn new_copy(brush: impl CastInto<Ref<QBrush>>) -> CppBox<QBrush>
pub unsafe fn new_copy(brush: impl CastInto<Ref<QBrush>>) -> CppBox<QBrush>
Constructs a copy of other.
Calls C++ function: [constructor] void QBrush::QBrush(const QBrush& brush)
.
Constructs a copy of other.
sourcepub unsafe fn set_color_q_color(&self, color: impl CastInto<Ref<QColor>>)
pub unsafe fn set_color_q_color(&self, color: impl CastInto<Ref<QColor>>)
Sets the brush color to the given color.
Calls C++ function: void QBrush::setColor(const QColor& color)
.
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 color().
sourcepub unsafe fn set_color_global_color(&self, color: GlobalColor)
pub unsafe fn set_color_global_color(&self, color: GlobalColor)
This is an overloaded function.
Calls C++ function: void QBrush::setColor(Qt::GlobalColor color)
.
This is an overloaded function.
Sets the brush color to the given color.
sourcepub unsafe fn set_matrix(&self, mat: impl CastInto<Ref<QMatrix>>)
pub unsafe fn set_matrix(&self, mat: impl CastInto<Ref<QMatrix>>)
Sets 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.
Calls C++ function: void QBrush::setMatrix(const QMatrix& mat)
.
sourcepub unsafe fn set_style(&self, arg1: BrushStyle)
pub unsafe fn set_style(&self, arg1: BrushStyle)
Sets the brush style to style.
Calls C++ function: void QBrush::setStyle(Qt::BrushStyle arg1)
.
Sets the brush style to style.
See also style().
sourcepub unsafe fn set_texture(&self, pixmap: impl CastInto<Ref<QPixmap>>)
pub unsafe fn set_texture(&self, pixmap: impl CastInto<Ref<QPixmap>>)
Sets the brush pixmap to pixmap. The style is set to Qt::TexturePattern.
Calls C++ function: void QBrush::setTexture(const QPixmap& pixmap)
.
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).
See also texture().
sourcepub unsafe fn set_texture_image(&self, image: impl CastInto<Ref<QImage>>)
pub unsafe fn set_texture_image(&self, image: impl CastInto<Ref<QImage>>)
Sets the brush image to image. The style is set to Qt::TexturePattern.
Calls C++ function: void QBrush::setTextureImage(const QImage& image)
.
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 a 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.
This function was introduced in Qt 4.2.
See also textureImage() and setTexture().
sourcepub unsafe fn set_transform(&self, arg1: impl CastInto<Ref<QTransform>>)
pub unsafe fn set_transform(&self, arg1: impl CastInto<Ref<QTransform>>)
Sets 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.
Calls C++ function: void QBrush::setTransform(const QTransform& arg1)
.
sourcepub unsafe fn style(&self) -> BrushStyle
pub unsafe fn style(&self) -> BrushStyle
Returns the brush style.
Calls C++ function: Qt::BrushStyle QBrush::style() const
.
Returns the brush style.
See also setStyle().
sourcepub unsafe fn swap(&self, other: impl CastInto<Ref<QBrush>>)
pub unsafe fn swap(&self, other: impl CastInto<Ref<QBrush>>)
Swaps brush other with this brush. This operation is very fast and never fails.
Calls C++ function: void QBrush::swap(QBrush& other)
.
Swaps brush other with this brush. This operation is very fast and never fails.
This function was introduced in Qt 4.8.
sourcepub unsafe fn texture(&self) -> CppBox<QPixmap>
pub unsafe fn texture(&self) -> CppBox<QPixmap>
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
Calls C++ function: QPixmap QBrush::texture() const
.
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
See also setTexture().
sourcepub unsafe fn texture_image(&self) -> CppBox<QImage>
pub unsafe fn texture_image(&self) -> CppBox<QImage>
Returns the custom brush pattern, or a null image if no custom brush pattern has been set.
Calls C++ function: QImage QBrush::textureImage() const
.
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.
This function was introduced in Qt 4.2.
See also setTextureImage().
sourcepub unsafe fn to_q_variant(&self) -> CppBox<QVariant>
pub unsafe fn to_q_variant(&self) -> CppBox<QVariant>
sourcepub unsafe fn transform(&self) -> CppBox<QTransform>
pub unsafe fn transform(&self) -> CppBox<QTransform>
Returns the current transformation matrix for the brush.
Calls C++ function: QTransform QBrush::transform() const
.
Returns the current transformation matrix for the brush.
This function was introduced in Qt 4.3.
See also setTransform().
Trait Implementations§
source§impl CppDeletable for QBrush
impl CppDeletable for QBrush
source§impl PartialEq<Ref<QBrush>> for QBrush
impl PartialEq<Ref<QBrush>> for QBrush
source§fn eq(&self, b: &Ref<QBrush>) -> bool
fn eq(&self, b: &Ref<QBrush>) -> bool
Returns true
if the brush is equal to the given brush; otherwise returns false
.
Calls C++ function: bool QBrush::operator==(const QBrush& b) const
.
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 operator!=().