[][src]Struct qt_gui::QBrush

#[repr(C)]pub struct QBrush { /* fields omitted */ }

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.

Methods

impl QBrush[src]

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

Returns the brush color.

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

C++ documentation:

Returns the brush color.

See also setColor().

pub unsafe fn copy_from(&self, brush: impl CastInto<Ref<QBrush>>) -> Ref<QBrush>[src]

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.

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

Returns the gradient describing this brush.

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

C++ documentation:

Returns the gradient describing this brush.

pub unsafe fn is_detached(&self) -> bool[src]

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

pub unsafe fn is_opaque(&self) -> bool[src]

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.

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

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

pub unsafe fn new() -> CppBox<QBrush>[src]

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

pub unsafe fn from_brush_style(bs: BrushStyle) -> CppBox<QBrush>[src]

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

pub unsafe fn from_q_color_brush_style(
    color: impl CastInto<Ref<QColor>>,
    bs: BrushStyle
) -> CppBox<QBrush>
[src]

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

pub unsafe fn from_global_color_brush_style(
    color: GlobalColor,
    bs: BrushStyle
) -> CppBox<QBrush>
[src]

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

pub unsafe fn from_q_color_q_pixmap(
    color: impl CastInto<Ref<QColor>>,
    pixmap: impl CastInto<Ref<QPixmap>>
) -> CppBox<QBrush>
[src]

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

pub unsafe fn from_global_color_q_pixmap(
    color: GlobalColor,
    pixmap: impl CastInto<Ref<QPixmap>>
) -> CppBox<QBrush>
[src]

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

pub unsafe fn from_q_pixmap(
    pixmap: impl CastInto<Ref<QPixmap>>
) -> CppBox<QBrush>
[src]

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

pub unsafe fn from_q_image(image: impl CastInto<Ref<QImage>>) -> CppBox<QBrush>[src]

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

pub unsafe fn from_q_gradient(
    gradient: impl CastInto<Ref<QGradient>>
) -> CppBox<QBrush>
[src]

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

pub unsafe fn from_q_color(color: impl CastInto<Ref<QColor>>) -> CppBox<QBrush>[src]

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

pub unsafe fn from_global_color(color: GlobalColor) -> CppBox<QBrush>[src]

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

pub unsafe fn new_copy(brush: impl CastInto<Ref<QBrush>>) -> CppBox<QBrush>[src]

Constructs a copy of other.

Calls C++ function: [constructor] void QBrush::QBrush(const QBrush& brush).

C++ documentation:

Constructs a copy of other.

pub unsafe fn set_color_q_color(&self, color: impl CastInto<Ref<QColor>>)[src]

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

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

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.

pub unsafe fn set_matrix(&self, mat: impl CastInto<Ref<QMatrix>>)[src]

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

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

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

pub unsafe fn set_texture(&self, pixmap: impl CastInto<Ref<QPixmap>>)[src]

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

pub unsafe fn set_texture_image(&self, image: impl CastInto<Ref<QImage>>)[src]

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

pub unsafe fn set_transform(&self, arg1: impl CastInto<Ref<QTransform>>)[src]

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

pub unsafe fn style(&self) -> BrushStyle[src]

Returns the brush style.

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

C++ documentation:

Returns the brush style.

See also setStyle().

pub unsafe fn swap(&self, other: impl CastInto<Ref<QBrush>>)[src]

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.

pub unsafe fn texture(&self) -> CppBox<QPixmap>[src]

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

pub unsafe fn texture_image(&self) -> CppBox<QImage>[src]

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

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

Returns the brush as a QVariant

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

C++ documentation:

Returns the brush as a QVariant

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

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

impl CppDeletable for QBrush[src]

unsafe fn delete(&self)[src]

Destroys the brush.

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

C++ documentation:

Destroys the brush.

impl PartialEq<Ref<QBrush>> for QBrush[src]

fn eq(&self, b: &Ref<QBrush>) -> bool[src]

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

Auto Trait Implementations

impl RefUnwindSafe for QBrush

impl Send for QBrush

impl Sync for QBrush

impl Unpin for QBrush

impl UnwindSafe for QBrush

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.