Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QBrush Class Reference
[QtGui module]

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

#include <QBrush>

Public Functions

  • 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 QBrush & other )
  • QBrush ( const QGradient & gradient )
  • 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 )
  • Qt::BrushStyle style () const
  • QPixmap texture () const
  • bool operator!= ( const QBrush & brush ) const
  • QBrush & operator= ( const QBrush & brush )
  • bool operator== ( const QBrush & brush ) const

Related Non-Members

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

Detailed Description

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

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 appropiate 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. The gradient can only be set when constructing the brush, while the texture() can be set using the appropiate constructor or by using the setTexture() function. The texture() defines the pixmap used when the current style is Qt::TexturePattern.

Note that applying setTexture() makes style() == Qt::TexturePattern, independently 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:

  • The alpha component of the color() is 255.
  • Its texture() does not an alpha channel and is not a QBitmap.
  • The colors in the gradient() all have an alpha component that is 255.

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

For more information about painting in general, see {The Paint System} documentation.

See also Qt::BrushStyle, QPainter, and QColor.


Member Function Documentation

QBrush::QBrush ()

Constructs a default black brush with the style Qt::NoBrush (i.e. this brush will not fill shapes).

QBrush::QBrush ( Qt::BrushStyle style )

Constructs a black brush with the given style.

See also setStyle().

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

Constructs a brush with the given color and style.

See also setColor() and setStyle().

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

Constructs a brush with the given color and style.

See also setColor() and setStyle().

QBrush::QBrush ( const QColor & 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.

See also setColor() and setPixmap().

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.

See also setColor() and setPixmap().

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.

See also setTexture().

QBrush::QBrush ( const QBrush & other )

Constructs a copy of 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.

See also setColor().

const QGradient * QBrush::gradient () const

Returns the gradient describing this brush.

bool QBrush::isOpaque () const

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

  • The alpha component of the color() is 255.
  • Its texture() does not an alpha channel and is not a QBitmap.
  • The colors in the gradient() all have an alpha component that is 255.

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.

See also color().

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

This is an overloaded member function, provided for convenience.

Sets the brush color to the given color.

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

Sets the brush style to style.

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

See also texture().

Qt::BrushStyle QBrush::style () const

Returns the brush style.

See also setStyle().

QPixmap QBrush::texture () const

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

See also setTexture().

QBrush::operator QVariant () const

Returns the brush as a QVariant

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

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

See also operator==().

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

Assigns the given brush to this brush and returns a reference to this brush.

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

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

See also operator!=().


Related Non-Members

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

This is an overloaded member function, provided for convenience.

Writes the given brush to the given stream and returns a reference to the stream.

See also Format of the QDataStream Operators.

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

This is an overloaded member function, provided for convenience.

Reads the given brush from the given stream and returns a reference to the stream.

See also Format of the QDataStream Operators.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Developer Network au hasard

Logo

Livre blanc de l'outillage de Qt Quick

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.1
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web