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  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QGraphicsEffect Class Reference
[QtGui module]

The QGraphicsEffect class is the base class for all graphics effects. More...

 #include <QGraphicsEffect>

Inherits QObject.

Inherited by QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffect, and QGraphicsOpacityEffect.

This class was introduced in Qt 4.6.


Public Types

enum ChangeFlag { SourceAttached, SourceDetached, SourceBoundingRectChanged, SourceInvalidated }
flags ChangeFlags
enum PixmapPadMode { NoPad, PadToTransparentBorder, PadToEffectiveBoundingRect }

Properties

  • 1 property inherited from QObject

Public Functions

QGraphicsEffect ( QObject * parent = 0 )
virtual ~QGraphicsEffect ()
QRectF boundingRect () const
virtual QRectF boundingRectFor ( const QRectF & rect ) const
bool isEnabled () const
  • 29 public functions inherited from QObject

Public Slots

void setEnabled ( bool enable )
void update ()
  • 1 public slot inherited from QObject

Signals

void enabledChanged ( bool enabled )

Protected Functions

virtual void draw ( QPainter * painter ) = 0
void drawSource ( QPainter * painter )
QRectF sourceBoundingRect ( Qt::CoordinateSystem system = Qt::LogicalCoordinates ) const
virtual void sourceChanged ( ChangeFlags flags )
bool sourceIsPixmap () const
QPixmap sourcePixmap ( Qt::CoordinateSystem system = Qt::LogicalCoordinates, QPoint * offset = 0, PixmapPadMode mode = PadToEffectiveBoundingRect ) const
void updateBoundingRect ()
  • 7 protected functions inherited from QObject

Additional Inherited Members

  • 5 static public members inherited from QObject

Detailed Description

The QGraphicsEffect class is the base class for all graphics effects.

Effects alter the appearance of elements by hooking into the rendering pipeline and operating between the source (e.g., a QGraphicsPixmapItem) and the destination device (e.g., QGraphicsView's viewport). Effects can be disabled by calling setEnabled(false). If effects are disabled, the source is rendered directly.

To add a visual effect to a QGraphicsItem, for example, you can use one of the standard effects, or alternately, create your own effect by creating a subclass of QGraphicsEffect. The effect can then be installed on the item using QGraphicsItem::setGraphicsEffect().

Qt provides the following standard effects:

For more information on how to use each effect, refer to the specific effect's documentation.

To create your own custom effect, create a subclass of QGraphicsEffect (or any other existing effects) and reimplement the virtual function draw(). This function is called whenever the effect needs to redraw. The draw() function takes the painter with which to draw as an argument. For more information, refer to the documenation for draw(). In the draw() function you can call sourcePixmap() to get a pixmap of the graphics effect source which you can then process.

If your effect changes, use update() to request for a redraw. If your custom effect changes the bounding rectangle of the source, e.g., a radial glow effect may need to apply an extra margin, you can reimplement the virtual boundingRectFor() function, and call updateBoundingRect() to notify the framework whenever this rectangle changes. The virtual sourceChanged() function is called to notify the effects that the source has changed in some way - e.g., if the source is a QGraphicsRectItem and its rectangle parameters have changed.

See also QGraphicsItem::setGraphicsEffect() and QWidget::setGraphicsEffect().


Member Type Documentation

enum QGraphicsEffect::ChangeFlag
flags QGraphicsEffect::ChangeFlags

This enum describes what has changed in QGraphicsEffectSource.

ConstantValueDescription
QGraphicsEffect::SourceAttached0x1The effect is installed on a source.
QGraphicsEffect::SourceDetached0x2The effect is uninstalled on a source.
QGraphicsEffect::SourceBoundingRectChanged0x4The bounding rect of the source has changed.
QGraphicsEffect::SourceInvalidated0x8The visual appearance of the source has changed.

The ChangeFlags type is a typedef for QFlags<ChangeFlag>. It stores an OR combination of ChangeFlag values.

enum QGraphicsEffect::PixmapPadMode

This enum describes how the pixmap returned from sourcePixmap should be padded.

ConstantValueDescription
QGraphicsEffect::NoPad0The pixmap should not receive any additional padding.
QGraphicsEffect::PadToTransparentBorder1The pixmap should be padded to ensure it has a completely transparent border.
QGraphicsEffect::PadToEffectiveBoundingRect2The pixmap should be padded to match the effective bounding rectangle of the effect.


Property Documentation

enabled : bool

This property holds whether the effect is enabled or not.

If an effect is disabled, the source will be rendered with as normal, with no interference from the effect. If the effect is enabled, the source will be rendered with the effect applied.

This property is enabled by default.

Using this property, you can disable certain effects on slow platforms, in order to ensure that the user interface is responsive.

Access functions:

bool isEnabled () const
void setEnabled ( bool enable )

Notifier signal:

void enabledChanged ( bool enabled )

Member Function Documentation

QGraphicsEffect::QGraphicsEffect ( QObject * parent = 0 )

Constructs a new QGraphicsEffect instance having the specified parent.

QGraphicsEffect::~QGraphicsEffect ()   [virtual]

Removes the effect from the source, and destroys the graphics effect.

QRectF QGraphicsEffect::boundingRect () const

Returns the effective bounding rectangle for this effect, i.e., the bounding rectangle of the source in device coordinates, adjusted by any margins applied by the effect itself.

See also boundingRectFor() and updateBoundingRect().

QRectF QGraphicsEffect::boundingRectFor ( const QRectF & rect ) const   [virtual]

Returns the effective bounding rectangle for this effect, given the provided rect in the device coordinates. When writing you own custom effect, you must call updateBoundingRect() whenever any parameters are changed that may cause this this function to return a different value.

See also sourceBoundingRect().

void QGraphicsEffect::draw ( QPainter * painter )   [pure virtual protected]

This pure virtual function draws the effect and is called whenever the source needs to be drawn.

Reimplement this function in a QGraphicsEffect subclass to provide the effect's drawing implementation, using painter.

For example:

 MyGraphicsEffect::draw(QPainter *painter)
 {
     ...
     QPoint offset;
     if (sourceIsPixmap()) {
         // No point in drawing in device coordinates (pixmap will be scaled anyways).
         const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset);
         ...
         painter->drawPixmap(offset, pixmap);
     } else {
         // Draw pixmap in device coordinates to avoid pixmap scaling;
         const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset);
         painter->setWorldTransform(QTransform());
         ...
         painter->drawPixmap(offset, pixmap);
     }
     ...
 }

This function should not be called explicitly by the user, since it is meant for reimplementation purposes only.

void QGraphicsEffect::drawSource ( QPainter * painter )   [protected]

Draws the source directly using the given painter.

This function should only be called from QGraphicsEffect::draw().

For example:

 MyGraphicsOpacityEffect::draw(QPainter *painter)
 {
     // Fully opaque; draw directly without going through a pixmap.
     if (qFuzzyCompare(m_opacity, 1)) {
         drawSource(painter);
         return;
     }
     ...
 }

See also QGraphicsEffect::draw().

void QGraphicsEffect::enabledChanged ( bool enabled )   [signal]

This signal is emitted whenever the effect is enabled or disabled. The enabled parameter holds the effects's new enabled state.

See also isEnabled().

QRectF QGraphicsEffect::sourceBoundingRect ( Qt::CoordinateSystem system = Qt::LogicalCoordinates ) const   [protected]

Returns the bounding rectangle of the source mapped to the given system.

Calling this function with Qt::DeviceCoordinates outside of QGraphicsEffect::draw() will give undefined results, as there is no device context available.

See also draw().

void QGraphicsEffect::sourceChanged ( ChangeFlags flags )   [virtual protected]

This virtual function is called by QGraphicsEffect to notify the effect that the source has changed. If the effect applies any cache, then this cache must be purged in order to reflect the new appearance of the source.

The flags describes what has changed.

bool QGraphicsEffect::sourceIsPixmap () const   [protected]

Returns true if the source effectively is a pixmap, e.g., a QGraphicsPixmapItem.

This function is useful for optimization purposes. For instance, there's no point in drawing the source in device coordinates to avoid pixmap scaling if this function returns true - the source pixmap will be scaled anyways.

QPixmap QGraphicsEffect::sourcePixmap ( Qt::CoordinateSystem system = Qt::LogicalCoordinates, QPoint * offset = 0, PixmapPadMode mode = PadToEffectiveBoundingRect ) const   [protected]

Returns a pixmap with the source painted into it.

The system specifies which coordinate system to be used for the source. The optional offset parameter returns the offset where the pixmap should be painted at using the current painter. For control on how the pixmap is padded use the mode parameter.

The returned pixmap is clipped to the current painter's device rectangle when system is Qt::DeviceCoordinates.

Calling this function with Qt::DeviceCoordinates outside of QGraphicsEffect::draw() will give undefined results, as there is no device context available.

See also draw() and boundingRect().

void QGraphicsEffect::update ()   [slot]

Schedules a redraw of the source. Call this function whenever the source needs to be redrawn.

This convenience function is equivalent to calling QGraphicsEffectSource::update().

See also updateBoundingRect() and QGraphicsEffectSource::update().

void QGraphicsEffect::updateBoundingRect ()   [protected]

This function notifies the effect framework when the effect's bounding rectangle has changed. As a custom effect author, you must call this function whenever you change any parameters that will cause the virtual boundingRectFor() function to return a different value.

This function will call update() if this is necessary.

See also boundingRectFor(), boundingRect(), and sourceBoundingRect().

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 102
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 53
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 82
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 28
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 229
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 102
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le Qt Developer Network au hasard

Logo

Combiner licence, à propos et fermer d'une dernière manière

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.6-snapshot
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