Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QGraphicsEffect Class

TheQGraphicsEffect class is the base class for all graphics effects.More...

Header:#include <QGraphicsEffect>
Since: Qt 4.6
Inherits:QObject
Inherited By:

QGraphicsBlurEffect,QGraphicsColorizeEffect,QGraphicsDropShadowEffect, andQGraphicsOpacityEffect

Public Types

enumChangeFlag { SourceAttached, SourceDetached, SourceBoundingRectChanged, SourceInvalidated }
flagsChangeFlags
enumPixmapPadMode { NoPad, PadToTransparentBorder, PadToEffectiveBoundingRect }

Properties

Public Functions

QGraphicsEffect(QObject * parent = 0)
virtual~QGraphicsEffect()
QRectFboundingRect() const
virtual QRectFboundingRectFor(const QRectF & rect) const
boolisEnabled() const
  • 29 public functions inherited fromQObject

Public Slots

voidsetEnabled(bool enable)
voidupdate()
  • 1 public slot inherited fromQObject

Signals

voidenabledChanged(bool enabled)

Protected Functions

virtual voiddraw(QPainter * painter) = 0
voiddrawSource(QPainter * painter)
QRectFsourceBoundingRect(Qt::CoordinateSystem system = Qt::LogicalCoordinates) const
virtual voidsourceChanged(ChangeFlags flags)
boolsourceIsPixmap() const
QPixmapsourcePixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, QPoint * offset = 0, PixmapPadMode mode = PadToEffectiveBoundingRect) const
voidupdateBoundingRect()
  • 8 protected functions inherited fromQObject

Additional Inherited Members

  • 7 static public members inherited fromQObject

Detailed Description

TheQGraphicsEffect 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., aQGraphicsPixmapItem) and the destination device (e.g.,QGraphicsView's viewport). Effects can be disabled by callingsetEnabled(false). If effects are disabled, the source is rendered directly.

To add a visual effect to aQGraphicsItem, for example, you can use one of the standard effects, or alternately, create your own effect by creating a subclass ofQGraphicsEffect. The effect can then be installed on the item usingQGraphicsItem::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 ofQGraphicsEffect (or any other existing effects) and reimplement the virtual functiondraw(). This function is called whenever the effect needs to redraw. Thedraw() function takes the painter with which to draw as an argument. For more information, refer to the documenation fordraw(). In thedraw() function you can callsourcePixmap() to get a pixmap of the graphics effect source which you can then process.

If your effect changes, useupdate() 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 virtualboundingRectFor() function, and callupdateBoundingRect() to notify the framework whenever this rectangle changes. The virtualsourceChanged() function is called to notify the effects that the source has changed in some way - e.g., if the source is aQGraphicsRectItem and its rectangle parameters have changed.

See alsoQGraphicsItem::setGraphicsEffect() andQWidget::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 forQFlags<ChangeFlag>. It stores an OR combination of ChangeFlag values.

enum QGraphicsEffect::PixmapPadMode

This enum describes how the pixmap returned fromsourcePixmap 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:

boolisEnabled() const
voidsetEnabled(bool enable)

Notifier signal:

voidenabledChanged(bool enabled)

Member Function Documentation

QGraphicsEffect::QGraphicsEffect(QObject * parent = 0)

Constructs a newQGraphicsEffect instance having the specifiedparent.

[virtual]QGraphicsEffect::~QGraphicsEffect()

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 alsoboundingRectFor() andupdateBoundingRect().

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

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

See alsosourceBoundingRect().

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

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

Reimplement this function in aQGraphicsEffect subclass to provide the effect's drawing implementation, usingpainter.

For example:

MyGraphicsEffect::draw(QPainter*painter){...QPoint offset;if (sourceIsPixmap()) {// No point in drawing in device coordinates (pixmap will be scaled anyways).constQPixmap pixmap= sourcePixmap(Qt::LogicalCoordinates,&offset);...        painter->drawPixmap(offset, pixmap);    }else {// Draw pixmap in device coordinates to avoid pixmap scaling;constQPixmap 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.

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

Draws the source directly using the givenpainter.

This function should only be called fromQGraphicsEffect::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 alsoQGraphicsEffect::draw().

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

Returns the bounding rectangle of the source mapped to the givensystem.

Calling this function withQt::DeviceCoordinates outside ofQGraphicsEffect::draw() will give undefined results, as there is no device context available.

See alsodraw().

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

This virtual function is called byQGraphicsEffect 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.

Theflags describes what has changed.

[protected]bool QGraphicsEffect::sourceIsPixmap() const

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

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.

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

Returns a pixmap with the source painted into it.

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

The returned pixmap is clipped to the current painter's device rectangle whensystem isQt::DeviceCoordinates.

Calling this function withQt::DeviceCoordinates outside ofQGraphicsEffect::draw() will give undefined results, as there is no device context available.

See alsodraw() andboundingRect().

[slot]void QGraphicsEffect::update()

Schedules a redraw of the effect. Call this function whenever the effect needs to be redrawn. This function does not trigger a redraw of the source.

See alsoupdateBoundingRect().

[protected]void QGraphicsEffect::updateBoundingRect()

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 virtualboundingRectFor() function to return a different value.

This function will callupdate() if this is necessary.

See alsoboundingRectFor(),boundingRect(), andsourceBoundingRect().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp