QBrush 类

The QBrush 类定义填充图案为绘制形状通过 QPainter . 更多...

头: #include <QBrush>
qmake: QT += gui

公共函数

QBrush ()
QBrush (Qt::BrushStyle style )
QBrush (const QColor & color , Qt::BrushStyle style = Qt::SolidPattern)
QBrush (Qt::GlobalColor color , Qt::BrushStyle style = Qt::SolidPattern)
QBrush (const QColor & color , const QPixmap & pixmap )
QBrush (Qt::GlobalColor color , const QPixmap & pixmap )
QBrush (const QPixmap & pixmap )
QBrush (const QImage & image )
QBrush (const QBrush & other )
QBrush (const QGradient & gradient )
~QBrush ()
const QColor & color () const
const QGradient * gradient () const
bool isOpaque () const
const QMatrix & matrix () const
void setColor (const QColor & color )
void setColor (Qt::GlobalColor color )
void setMatrix (const QMatrix & matrix )
void setStyle (Qt::BrushStyle style )
void setTexture (const QPixmap & pixmap )
void setTextureImage (const QImage & image )
void setTransform (const QTransform & matrix )
Qt::BrushStyle style () const
void swap (QBrush & other )
QPixmap texture () const
QImage textureImage () const
QTransform transform () const
operator QVariant () const
bool operator!= (const QBrush & brush ) const
QBrush & operator= (const QBrush & brush )
QBrush & operator= (QBrush && other )
bool operator== (const QBrush & brush ) const
QDataStream & operator<< (QDataStream & stream , const QBrush & brush )
QDataStream & operator>> (QDataStream & stream , QBrush & brush )

详细描述

The QBrush 类定义填充图案为绘制形状通过 QPainter .

笔刷拥有样式、颜色、渐变和纹理。

笔刷 style () 定义填充图案使用 Qt::BrushStyle 枚举。默认笔刷样式为 Qt::NoBrush (从属如何构造笔刷)。此风格告诉描绘器不要填充形状。标准填充样式为 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

笔刷 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 () 和 setColor () 函数,分别。

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 ,和 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 () 使 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 () 函数返回 true if the brush is fully opaque otherwise false. A brush is considered opaque if:

Outlines To 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.

一般而言,有关描绘的更多信息,见 描绘系统 .

另请参阅 Qt::BrushStyle , QPainter ,和 QColor .

成员函数文档编制

QBrush:: QBrush ()

构造默认黑色笔刷采用样式 Qt::NoBrush (即:该笔刷不会填充形状)。

QBrush:: QBrush ( Qt::BrushStyle style )

构造黑色笔刷采用给定 style .

另请参阅 setStyle ().

QBrush:: QBrush (const QColor & color , Qt::BrushStyle style = Qt::SolidPattern)

构造笔刷采用给定 color and style .

另请参阅 setColor () 和 setStyle ().

QBrush:: QBrush ( Qt::GlobalColor color , Qt::BrushStyle style = Qt::SolidPattern)

构造笔刷采用给定 color and style .

另请参阅 setColor () 和 setStyle ().

QBrush:: QBrush (const QColor & color , const QPixmap & pixmap )

构造笔刷采用给定 color and the custom pattern stored in pixmap .

The style is set to Qt::TexturePattern . The color will only have an effect for QBitmaps.

另请参阅 setColor () 和 setTexture ().

QBrush:: QBrush ( Qt::GlobalColor color , const QPixmap & pixmap )

构造笔刷采用给定 color and the custom pattern stored in pixmap .

The style is set to Qt::TexturePattern . The color will only have an effect for QBitmaps.

另请参阅 setColor () 和 setTexture ().

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 .

另请参阅 setTexture ().

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 .

另请参阅 setTextureImage ().

QBrush:: QBrush (const QBrush & other )

构造副本为 other .

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

QBrush:: ~QBrush ()

Destroys the brush.

const QColor &QBrush:: color () const

Returns the brush color.

另请参阅 setColor ().

const QGradient *QBrush:: gradient () const

Returns the gradient describing this brush.

bool QBrush:: isOpaque () const

返回 true if the brush is fully opaque otherwise false. A brush is considered opaque if:

  • Alpha 分量对于 color () 为 255。
  • Its texture () 没有 Alpha 通道,且不是 QBitmap .
  • The colors in the gradient () all have an alpha component that is 255.
  • It is an extended radial gradient.

const QMatrix &QBrush:: matrix () const

Returns the current transformation matrix for the brush.

该函数在 Qt 4.2 引入。

另请参阅 setMatrix ().

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 .

另请参阅 color ().

void QBrush:: setColor ( Qt::GlobalColor color )

这是重载函数。

Sets the brush color to the given color .

void QBrush:: setMatrix (const QMatrix & matrix )

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.

该函数在 Qt 4.2 引入。

另请参阅 matrix ().

void QBrush:: setStyle ( Qt::BrushStyle style )

Sets the brush style to style .

另请参阅 style ().

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

另请参阅 texture ().

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

该函数在 Qt 4.2 引入。

另请参阅 textureImage () 和 setTexture ().

void QBrush:: setTransform (const QTransform & matrix )

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.

该函数在 Qt 4.3 引入。

另请参阅 transform ().

Qt::BrushStyle QBrush:: style () const

Returns the brush style.

另请参阅 setStyle ().

void QBrush:: swap ( QBrush & other )

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

该函数在 Qt 4.8 引入。

QPixmap QBrush:: texture () const

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

另请参阅 setTexture ().

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 .

该函数在 Qt 4.2 引入。

另请参阅 setTextureImage ().

QTransform QBrush:: transform () const

Returns the current transformation matrix for the brush.

该函数在 Qt 4.3 引入。

另请参阅 setTransform ().

QBrush:: operator QVariant () const

Returns the brush as a QVariant

bool QBrush:: operator!= (const QBrush & brush ) const

返回 true if the brush is different from the given brush ;否则返回 false .

Two brushes are different if they have different styles, colors or transforms or different pixmaps or gradients depending on the style.

另请参阅 operator== ().

QBrush &QBrush:: operator= (const QBrush & brush )

赋值给定 brush to this brush and returns a reference to this 笔刷。

QBrush &QBrush:: operator= ( QBrush && other )

移动赋值 other 到此 QBrush 实例。

该函数在 Qt 5.2 引入。

bool QBrush:: operator== (const QBrush & brush ) const

返回 true if the brush is equal to the given brush ;否则返回 false .

Two brushes are equal if they have equal styles, colors and transforms and equal pixmaps or gradients depending on the style.

另请参阅 operator!= ().

相关非成员

QDataStream & operator<< ( QDataStream & stream , const QBrush & brush )

写入给定 brush 到给定 stream 并返回引用针对 stream .

另请参阅 序列化 Qt 数据类型 .

QDataStream & operator>> ( QDataStream & stream , QBrush & brush )

读取给定 brush 从给定 stream 并返回引用针对 stream .

另请参阅 序列化 Qt 数据类型 .