pub struct Brush<'a> { /* private fields */ }
Expand description
Notice these docs are heavy WIP and not very relevent yet
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.
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 \c painter.setPen(Qt::NoPen) to disable this behavior.
For more information about painting in general, see the Paint System
See also: [t::brush_style()
]
Painter
Color
Licence
The documentation is an adoption of the original Qt Documentation and provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Implementations
sourceimpl<'a> Brush<'a>
impl<'a> Brush<'a>
pub fn new() -> Brush<'a>
sourcepub fn swap<B: BrushTrait<'a>>(&self, other: &B) -> &Self
pub fn swap<B: BrushTrait<'a>>(&self, other: &B) -> &Self
Swaps brush other with this brush. This operation is very fast and never fails.
sourcepub fn style(&self) -> BrushStyle
pub fn style(&self) -> BrushStyle
Returns the brush style.
See also: [set_style()
]
sourcepub fn set_style(&self, arg0: BrushStyle) -> &Self
pub fn set_style(&self, arg0: BrushStyle) -> &Self
Sets the brush style to style.
See also: [style()
]
sourcepub fn set_transform<T: TransformTrait<'a>>(&self, arg0: &T) -> &Self
pub fn set_transform<T: TransformTrait<'a>>(&self, arg0: &T) -> &Self
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.
See also: [transform()
]
sourcepub fn texture(&self) -> Pixmap<'_>
pub fn texture(&self) -> Pixmap<'_>
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
See also: [set_texture()
]
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.
See also: [set_texture_image()
]
sourcepub fn set_texture<P: PixmapTrait<'a>>(&self, pixmap: &P) -> &Self
pub fn set_texture<P: PixmapTrait<'a>>(&self, pixmap: &P) -> &Self
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()
]
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.
See also: [texture_image()
]
[set_texture()
]
sourcepub fn texture_image(&self) -> Image<'_>
pub fn texture_image(&self) -> Image<'_>
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.
See also: [set_texture_image()
]
sourcepub fn set_texture_image<I: ImageTrait<'a>>(&self, image: &I) -> &Self
pub fn set_texture_image<I: ImageTrait<'a>>(&self, image: &I) -> &Self
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.
See also: [texture_image()
]
[set_texture()
]
sourcepub fn set_color<C: ColorTrait<'a>>(&self, color: &C) -> &Self
pub fn set_color<C: ColorTrait<'a>>(&self, color: &C) -> &Self
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()
]
Overloads Sets the brush color to the given color.
sourcepub fn set_color_2(&self, color: GlobalColor) -> &Self
pub fn set_color_2(&self, color: GlobalColor) -> &Self
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()
]
Overloads Sets the brush color to the given color.
sourcepub fn is_opaque(&self) -> bool
pub fn is_opaque(&self) -> 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 a QBitmap.
- The colors in the gradient() all have an alpha component that is 255.
- It is an extended radial gradient.