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.
筆刷 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:
|
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
|
一般而言,有關描繪的更多信息,見 描繪係統 .
另請參閱 Qt::BrushStyle , QPainter ,和 QColor .
構造默認黑色筆刷采用樣式 Qt::NoBrush (即:該筆刷不會填充形狀)。
構造黑色筆刷采用給定 style .
另請參閱 setStyle ().
構造筆刷采用給定 color and style .
另請參閱 setColor () 和 setStyle ().
構造筆刷采用給定 color and style .
另請參閱 setColor () 和 setStyle ().
構造筆刷采用給定 color and the custom pattern stored in pixmap .
樣式被設為 Qt::TexturePattern . The color will only have an effect for QBitmaps.
另請參閱 setColor () 和 setTexture ().
構造筆刷采用給定 color and the custom pattern stored in pixmap .
樣式被設為 Qt::TexturePattern . The color will only have an effect for QBitmaps.
另請參閱 setColor () 和 setTexture ().
Constructs a brush with a black color and a texture set to the given pixmap 。樣式被設為 Qt::TexturePattern .
另請參閱 setTexture ().
Constructs a brush with a black color and a texture set to the given image 。樣式被設為 Qt::TexturePattern .
另請參閱 setTextureImage ().
構造副本為 other .
構造筆刷基於給定 gradient .
The brush style is set to the corresponding gradient style (either Qt::LinearGradientPattern , Qt::RadialGradientPattern or Qt::ConicalGradientPattern ).
銷毀筆刷。
返迴筆刷顔色。
另請參閱 setColor ().
返迴描述此筆刷的漸變。
返迴
true
if the brush is fully opaque otherwise false. A brush is considered opaque if:
Returns the current transformation matrix for the brush.
該函數在 Qt 4.2 引入。
另請參閱 setMatrix ().
把筆刷顔色設為給定 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 ().
這是重載函數。
把筆刷顔色設為給定 color .
集 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 ().
把筆刷樣式設為 style .
另請參閱 style ().
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 ().
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 ().
集 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 ().
返迴筆刷樣式。
另請參閱 setStyle ().
Swaps brush other with this brush. This operation is very fast and never fails.
該函數在 Qt 4.8 引入。
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
另請參閱 setTexture ().
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 ().
Returns the current transformation matrix for the brush.
該函數在 Qt 4.3 引入。
另請參閱 setTransform ().
Returns the brush as a QVariant
返迴
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== ().
賦值給定 brush to this brush and returns a reference to this 筆刷。
移動賦值 other 到此 QBrush 實例。
該函數在 Qt 5.2 引入。
返迴
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!= ().
寫入給定 brush 到給定 stream 並返迴引用針對 stream .
另請參閱 序列化 Qt 數據類型 .
讀取給定 brush 從給定 stream 並返迴引用針對 stream .
另請參閱 序列化 Qt 數據類型 .