diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp b/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp new file mode 100644 index 0000000..6265c80 --- /dev/null +++ b/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp @@ -0,0 +1,33 @@ +//! [0] +MyGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +{ + // Fully opaque; draw directly without going through a pixmap. + if (qFuzzyCompare(m_opacity, 1)) { + source->draw(painter); + return; + } + ... +} +//! [0] + +//! [1] +MyGraphicsEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +{ + ... + QPoint offset; + if (source->isPixmap()) { + // No point in drawing in device coordinates (pixmap will be scaled anyways). + const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset); + ... + painter->drawPixmap(offset, pixmap); + } else { + // Draw pixmap in device coordinates to avoid pixmap scaling; + const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset); + painter->setWorldTransform(QTransform()); + ... + painter->drawPixmap(offset, pixmap); + } + ... +} +//! [1] + |