Struct qt_gui::QBrush

source ·
#[repr(C)]
pub struct QBrush { /* private fields */ }
Expand description

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

C++ class: QBrush.

C++ documentation:

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.

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

Implementations§

source§

impl QBrush

source

pub unsafe fn color(&self) -> Ref<QColor>

Returns the brush color.

Calls C++ function: const QColor& QBrush::color() const.

C++ documentation:

Returns the brush color.

See also setColor().

source

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

C++ documentation:

Assigns the given brush to this brush and returns a reference to this brush.

source

pub unsafe fn gradient(&self) -> Ptr<QGradient>

Returns the gradient describing this brush.

Calls C++ function: const QGradient* QBrush::gradient() const.

C++ documentation:

Returns the gradient describing this brush.

source

pub unsafe fn is_detached(&self) -> bool

Calls C++ function: bool QBrush::isDetached() const.

source

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.

C++ documentation:

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.
  • It is an extended radial gradient.
source

pub unsafe fn matrix(&self) -> Ref<QMatrix>

Returns the current transformation matrix for the brush.

Calls C++ function: const QMatrix& QBrush::matrix() const.

C++ documentation:

Returns the current transformation matrix for the brush.

This function was introduced in Qt 4.2.

See also setMatrix().

source

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

C++ documentation:

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

source

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

C++ documentation:

Constructs a black brush with the given style.

See also setStyle().

source

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 = …).

C++ documentation:

Constructs a brush with the given color and style.

See also setColor() and setStyle().

source

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 = …).

C++ documentation:

Constructs a brush with the given color and style.

See also setColor() and setStyle().

source

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

C++ documentation:

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

source

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

C++ documentation:

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

source

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

C++ documentation:

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

source

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

C++ documentation:

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

source

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

C++ documentation:

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

source

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

C++ documentation:

Constructs a brush with the given color and style.

See also setColor() and setStyle().

source

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

C++ documentation:

Constructs a brush with the given color and style.

See also setColor() and setStyle().

source

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

C++ documentation:

Constructs a copy of other.

source

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

C++ documentation:

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

source

pub unsafe fn set_color_global_color(&self, color: GlobalColor)

This is an overloaded function.

Calls C++ function: void QBrush::setColor(Qt::GlobalColor color).

C++ documentation:

This is an overloaded function.

Sets the brush color to the given color.

source

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

C++ documentation:

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.

This function was introduced in Qt 4.2.

See also matrix().

source

pub unsafe fn set_style(&self, arg1: BrushStyle)

Sets the brush style to style.

Calls C++ function: void QBrush::setStyle(Qt::BrushStyle arg1).

C++ documentation:

Sets the brush style to style.

See also style().

source

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

C++ documentation:

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

source

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

C++ documentation:

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

source

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

C++ documentation:

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.

This function was introduced in Qt 4.3.

See also transform().

source

pub unsafe fn style(&self) -> BrushStyle

Returns the brush style.

Calls C++ function: Qt::BrushStyle QBrush::style() const.

C++ documentation:

Returns the brush style.

See also setStyle().

source

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

C++ documentation:

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

This function was introduced in Qt 4.8.

source

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.

C++ documentation:

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

See also setTexture().

source

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.

C++ documentation:

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

source

pub unsafe fn to_q_variant(&self) -> CppBox<QVariant>

Returns the brush as a QVariant

Calls C++ function: QVariant QBrush::operator QVariant() const.

C++ documentation:

Returns the brush as a QVariant

source

pub unsafe fn transform(&self) -> CppBox<QTransform>

Returns the current transformation matrix for the brush.

Calls C++ function: QTransform QBrush::transform() const.

C++ documentation:

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

source§

unsafe fn delete(&self)

Destroys the brush.

Calls C++ function: [destructor] void QBrush::~QBrush().

C++ documentation:

Destroys the brush.

source§

impl PartialEq<Ref<QBrush>> for QBrush

source§

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.

C++ documentation:

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!=().

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.