QtBase
v6.3.1
|
The QBrush class defines the fill pattern of shapes drawn by QPainter. More...
#include <qbrush.h>
Public Types | |
using | DataPtr = std::unique_ptr< QBrushData, QBrushDataPointerDeleter > |
Friends | |
class | QRasterPaintEngine |
class | QRasterPaintEnginePrivate |
struct | QSpanData |
class | QPainter |
bool Q_GUI_EXPORT | qHasPixmapTexture (const QBrush &brush) |
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &stream, const QBrush &brush) |
QDataStream & | operator>> (QDataStream &stream, QBrush &brush) |
The QBrush class defines the fill pattern of shapes drawn by QPainter.
\inmodule QtGui
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
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:
\list
\table 100% \row
To specify the style and color of lines and outlines, use the QPainter's \l {QPen}{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 \l {Qt::NoPen}{painter.setPen(Qt::NoPen)}
to disable this behavior.
\endtable
For more information about painting in general, see the \l{Paint System}.
QBrush::QBrush | ( | ) |
Constructs a default black brush with the style Qt::NoBrush (i.e. this brush will not fill shapes).
Definition at line 426 of file qbrush.cpp.
QBrush::QBrush | ( | Qt::BrushStyle | style | ) |
Constructs a black brush with the given style.
Definition at line 466 of file qbrush.cpp.
QBrush::QBrush | ( | const QColor & | color, |
Qt::BrushStyle | style = Qt::SolidPattern |
||
) |
Constructs a brush with the given color and style.
Definition at line 477 of file qbrush.cpp.
QBrush::QBrush | ( | Qt::GlobalColor | color, |
Qt::BrushStyle | style = Qt::SolidPattern |
||
) |
Constructs a brush with the given color and style.
Definition at line 494 of file qbrush.cpp.
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.
Definition at line 509 of file qbrush.cpp.
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.
Definition at line 525 of file qbrush.cpp.
Constructs a brush with a black color and a texture set to the given pixmap. The style is set to Qt::TexturePattern.
Definition at line 440 of file qbrush.cpp.
Constructs a brush with a black color and a texture set to the given image. The style is set to Qt::TexturePattern.
Definition at line 454 of file qbrush.cpp.
Constructs a copy of other.
Definition at line 535 of file qbrush.cpp.
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).
Definition at line 548 of file qbrush.cpp.
QBrush::~QBrush | ( | ) |
Destroys the brush.
Definition at line 571 of file qbrush.cpp.
Returns the brush color.
Definition at line 157 of file qbrush.h.
Returns the gradient describing this brush.
Definition at line 824 of file qbrush.cpp.
bool QBrush::isOpaque | ( | ) | const |
Returns true
if the brush is fully opaque otherwise false. A brush is considered opaque if:
\list
Definition at line 863 of file qbrush.cpp.
QBrush::operator QVariant | ( | ) | const |
Returns the brush as a QVariant
Definition at line 669 of file qbrush.cpp.
|
inline |
Returns true
if the brush is different from the given brush; otherwise returns false
.
Two brushes are different if they have different styles, colors or transforms or different pixmaps or gradients depending on the style.
Definition at line 111 of file qbrush.h.
Assigns the given brush to this brush and returns a reference to this brush.
Move-assigns other to this QBrush instance.
Definition at line 640 of file qbrush.cpp.
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.
Definition at line 931 of file qbrush.cpp.
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.
Definition at line 720 of file qbrush.cpp.
|
inline |
void QBrush::setStyle | ( | Qt::BrushStyle | style | ) |
Sets the brush style to style.
Definition at line 688 of file qbrush.cpp.
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 (\l {QBitmap}{QBitmaps}).
Definition at line 761 of file qbrush.cpp.
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.
Definition at line 809 of file qbrush.cpp.
void QBrush::setTransform | ( | const QTransform & | matrix | ) |
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.
Definition at line 900 of file qbrush.cpp.
|
inline |
Returns the brush style.
Definition at line 156 of file qbrush.h.
QPixmap QBrush::texture | ( | ) | const |
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
Definition at line 744 of file qbrush.cpp.
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.
Definition at line 785 of file qbrush.cpp.
|
inline |
Returns the current transformation matrix for the brush.
Definition at line 158 of file qbrush.h.
|
related |
Writes the given brush to the given stream and returns a reference to the stream.
Definition at line 1031 of file qbrush.cpp.
|
related |
Reads the given brush from the given stream and returns a reference to the stream.
Definition at line 1107 of file qbrush.cpp.
Definition at line 235 of file qbrush.cpp.
|
friend |
|
friend |