QBrush 類

QBrush 類定義填充圖案為繪製形狀通過 QPainter . 更多...

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

公共函數

QBrush (const QGradient & gradient )
QBrush (const QBrush & other )
QBrush (const QImage & image )
QBrush (const QPixmap & pixmap )
QBrush (Qt::GlobalColor color , const QPixmap & pixmap )
QBrush (const QColor & color , const QPixmap & pixmap )
QBrush (Qt::GlobalColor color , Qt::BrushStyle style = Qt::SolidPattern)
QBrush (const QColor & color , Qt::BrushStyle style = Qt::SolidPattern)
QBrush (Qt::BrushStyle style )
QBrush ()
QBrush & operator= (QBrush && other )
QBrush & operator= (const QBrush & brush )
~QBrush ()
const QColor & color () const
const QGradient * gradient () const
bool isOpaque () const
void setColor (const QColor & color )
void setColor (Qt::GlobalColor color )
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
QVariant operator QVariant () const
bool operator!= (const QBrush & brush ) const
bool operator== (const QBrush & brush ) const
QDataStream & operator<< (QDataStream & stream , const QBrush & brush )
QDataStream & operator>> (QDataStream & stream , QBrush & brush )

詳細描述

筆刷擁有樣式、顔色、漸變和紋理。

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

注意,應用 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 (const QGradient & gradient )

構造筆刷基於給定 gradient .

The brush style is set to the corresponding gradient style (either Qt::LinearGradientPattern , Qt::RadialGradientPattern or Qt::ConicalGradientPattern ).

QBrush:: QBrush (const QBrush & other )

構造副本為 other .

QBrush:: QBrush (const QImage & image )

Constructs a brush with a black color and a texture set to the given image 。樣式被設為 Qt::TexturePattern .

另請參閱 setTextureImage ().

QBrush:: QBrush (const QPixmap & pixmap )

Constructs a brush with a black color and a texture set to the given pixmap 。樣式被設為 Qt::TexturePattern .

另請參閱 setTexture ().

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

構造筆刷采用給定 color and the custom pattern stored in pixmap .

樣式被設為 Qt::TexturePattern . The color will only have an effect for QBitmaps.

另請參閱 setColor () 和 setTexture ().

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

構造筆刷采用給定 color and the custom pattern stored in pixmap .

樣式被設為 Qt::TexturePattern . The color will only have an effect for QBitmaps.

另請參閱 setColor () 和 setTexture ().

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

構造筆刷采用給定 color and style .

另請參閱 setColor () 和 setStyle ().

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

構造筆刷采用給定 color and style .

另請參閱 setColor () 和 setStyle ().

QBrush:: QBrush ( Qt::BrushStyle style )

構造黑色筆刷采用給定 style .

另請參閱 setStyle ().

QBrush:: QBrush ()

構造默認黑色筆刷采用樣式 Qt::NoBrush (即:該筆刷不會填充形狀)。

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

移動賦值 other 到此 QBrush 實例。

該函數在 Qt 5.2 引入。

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

賦值給定 brush to this brush and returns a reference to this 筆刷。

QBrush:: ~QBrush ()

銷毀筆刷。

const QColor &QBrush:: color () const

返迴筆刷顔色。

另請參閱 setColor ().

const QGradient *QBrush:: gradient () const

返迴描述此筆刷的漸變。

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.

void QBrush:: setColor (const QColor & color )

把筆刷顔色設為給定 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 )

這是重載函數。

把筆刷顔色設為給定 color .

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

把筆刷樣式設為 style .

另請參閱 style ().

void QBrush:: setTexture (const QPixmap & pixmap )

Sets the brush pixmap to pixmap 。樣式被設為 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 。樣式被設為 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

返迴筆刷樣式。

另請參閱 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 ().

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

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

返迴 true 若筆刷等於給定 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 數據類型 .