返回介绍

QBrush Class

发布于 2019-10-04 14:58:22 字数 8113 浏览 972 评论 0 收藏 0

The QBrush class defines the fill pattern of shapes drawn by a QPainter. More...

#include <qbrush.h>

Inherits Qt.

List of all member functions.

Public Members

  • QBrush ()
  • QBrush ( BrushStylestyle )
  • QBrush ( constQColor&color, BrushStylestyle = SolidPattern )
  • QBrush ( constQColor&color, constQPixmap&pixmap )
  • QBrush ( constQBrush&b )
  • ~QBrush ()
  • QBrush & operator= ( constQBrush&b )
  • BrushStyle style () const
  • void setStyle ( BrushStyles )
  • const QColor & color () const
  • void setColor ( constQColor&c )
  • QPixmap * pixmap () const
  • void setPixmap ( constQPixmap&pixmap )
  • bool operator== ( constQBrush&b ) const
  • bool operator!= ( constQBrush&b ) const

Related Functions

  • QDataStream & operator<< ( QDataStream&s, constQBrush&b )
  • QDataStream & operator>> ( QDataStream&s, QBrush&b )

Detailed Description

The QBrush class defines the fill pattern of shapes drawn by a QPainter.

A brush has a style and a color. One of the brush styles is a custom pattern, which is defined by a QPixmap.

The brush style defines the fill pattern. The default brush style is NoBrush (depending on how you construct a brush). This style tells the painter to not fill shapes. The standard style for filling is SolidPattern.

The brush color defines the color of the fill pattern. The QColor documentation lists the predefined colors.

Use the QPen class for specifying line/outline styles.

Example:

        QPainter painter;
        QBrush   brush( yellow );           // yellow solid pattern
        painter.begin( &anyPaintDevice );   // paint something
        painter.setBrush( brush );          // set the yellow brush
        painter.setPen( NoPen );            // do not draw outline
        painter.drawRect( 40,30, 200,100 ); // draw filled rectangle
        painter.setBrush( NoBrush );        // do not fill
        painter.setPen( black );            // set black pen, 0 pixel width
        painter.drawRect( 10,10, 30,20 );   // draw rectangle outline
        painter.end();                      // painting done
    

See the setStyle() function for a complete list of brush styles.

Brush Styles

See also QPainter, QPainter::setBrush(), QPainter::setBrushOrigin(), Graphics Classes, Image Processing Classes and Implicitly and Explicitly Shared Classes.


Member Function Documentation

QBrush::QBrush ()

Constructs a default black brush with the style NoBrush (will not fill shapes).

QBrush::QBrush ( BrushStylestyle )

Constructs a black brush with the style style.

See also setStyle().

QBrush::QBrush ( constQColor&color, BrushStylestyle = SolidPattern )

Constructs a brush with the color color and the style style.

See also setColor() and setStyle().

QBrush::QBrush ( constQColor&color, constQPixmap&pixmap )

Constructs a brush with the color color and a custom pattern stored in pixmap.

The color will only have an effect for monochrome pixmaps, i.e. for QPixmap::depth() == 1.

See also setColor() and setPixmap().

QBrush::QBrush ( constQBrush&b )

Constructs a brush that is a shallow copy of b.

QBrush::~QBrush ()

Destroys the brush.

constQColor& QBrush::color () const

Returns the brush color.

See also setColor().

bool QBrush::operator!= ( constQBrush&b ) const

Returns TRUE if the brush is different from b; otherwise returns FALSE.

Two brushes are different if they have different styles, colors or pixmaps.

See also operator==().

QBrush& QBrush::operator= ( constQBrush&b )

Assigns b to this brush and returns a reference to this brush.

bool QBrush::operator== ( constQBrush&b ) const

Returns TRUE if the brush is equal to b; otherwise returns FALSE.

Two brushes are equal if they have equal styles, colors and pixmaps.

See also operator!=().

QPixmap* QBrush::pixmap () const

Returns a pointer to the custom brush pattern, or 0 if no custom brush pattern has been set.

See also setPixmap().

Example: richtext/richtext.cpp.

void QBrush::setColor ( constQColor&c )

Sets the brush color to c.

See also color() and setStyle().

Example: picture/picture.cpp.

void QBrush::setPixmap ( constQPixmap&pixmap )

Sets the brush pixmap to pixmap. The style is set to CustomPattern.

The current brush color will only have an effect for monochrome pixmaps, i.e. for QPixmap::depth() == 1.

See also pixmap() and color().

Example: richtext/richtext.cpp.

void QBrush::setStyle ( BrushStyles )

Sets the brush style to s.

The brush styles are:

PatternMeaning
NoBrushwill not fill shapes (default).
SolidPatternsolid (100%) fill pattern.
Dense1Pattern94% fill pattern.
Dense2Pattern88% fill pattern.
Dense3Pattern63% fill pattern.
Dense4Pattern50% fill pattern.
Dense5Pattern37% fill pattern.
Dense6Pattern12% fill pattern.
Dense7Pattern6% fill pattern.
HorPatternhorizontal lines pattern.
VerPatternvertical lines pattern.
CrossPatterncrossing lines pattern.
BDiagPatterndiagonal lines (directed /) pattern.
FDiagPatterndiagonal lines (directed \) pattern.
DiagCrossPatterndiagonal crossing lines pattern.
CustomPatternset when a pixmap pattern is being used.

On Windows, only the dense patterns are transparent.

See the Detailed Description for a picture of all the styles.

See also style().

BrushStyle QBrush::style () const

Returns the brush style.

See also setStyle().


Related Functions

QDataStream& operator<< ( QDataStream&s, constQBrush&b )

Writes the brush b to the stream s and returns a reference to the stream.

See also Format of the QDataStream operators.

QDataStream& operator>> ( QDataStream&s, QBrush&b )

Reads the brush b from the stream s and returns a reference to the stream.

See also Format of the QDataStream operators.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文