<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QGraphicsEffect and sourcePixmap()]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I've got some QGraphicsItem on wich I apply a custom QGraphicsEffect with its draw() function modified.  To acheive the desired effect I use the sourcePixmap() function like described in the doc.<br />
All is working well  but when I scale my view (zoom In) the QPixmap returned by sourcePixmap() get huge and I get "out of memory" errors and slowness.</p>
<p dir="auto">I could not find the source code of the sourcePixmap() function... Is there a way to render only the exposed rect of a QGraphicsItem into a QPixmap?</p>
<p dir="auto">Thank you</p>
]]></description><link>https://forum.qt.io/topic/79813/qgraphicseffect-and-sourcepixmap</link><generator>RSS for Node</generator><lastBuildDate>Fri, 30 Oct 2026 03:53:24 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/79813.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 31 May 2017 16:26:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QGraphicsEffect and sourcePixmap() on Thu, 01 Jun 2017 10:58:12 GMT]]></title><description><![CDATA[<p dir="auto">Here is a simplified code that reproduce the problem:</p>
<pre><code>#include &lt;QApplication&gt;
#include &lt;QtGui&gt;
#include &lt;QGraphicsScene&gt;
#include &lt;QGraphicsView&gt;
#include &lt;QGraphicsRectItem&gt;
#include &lt;QGraphicsEffect&gt;
#include &lt;QPainter&gt;
#include &lt;QBitmap&gt;
#include &lt;QDebug&gt;

class MYEffect : public QGraphicsEffect
{
public:
    MYEffect() : QGraphicsEffect() {}
    QRectF boundingRectFor(const QRectF&amp; sourceRect) const{
        return sourceRect;
    }

protected:
    void draw(QPainter* painter){
        QPoint offset;
        Qt::CoordinateSystem system = sourceIsPixmap() ? Qt::LogicalCoordinates : Qt::DeviceCoordinates;
        QPixmap pixmap = sourcePixmap(system, &amp;offset, QGraphicsEffect::NoPad);

        if (pixmap.isNull())
            return;

        qDebug() &lt;&lt; pixmap.size();

        painter-&gt;save();
        QPainter pixmapPainter(&amp;pixmap);
        pixmapPainter.setRenderHints(painter-&gt;renderHints());
        pixmapPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        QTransform worldTransform = painter-&gt;worldTransform();
        worldTransform *= QTransform::fromTranslate(-offset.x(), -offset.y());
        pixmapPainter.setWorldTransform(worldTransform);
        //pixmapPainter.fillRect(sourceBoundingRect(), Qt::blue);
        painter-&gt;setWorldTransform(QTransform());
        painter-&gt;setOpacity(0.5);
        painter-&gt;drawPixmap(offset, pixmap);
        painter-&gt;restore();
    }
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QGraphicsScene scene;
    scene.setSceneRect(0,0,50000,50000);

    MYEffect effect;

    QGraphicsRectItem rItem;
    rItem.setRect(20000,20000,10000,10000);
    rItem.setBrush(Qt::red);
    rItem.setGraphicsEffect(&amp;effect);

    scene.addItem(&amp;rItem);

    QGraphicsView view(&amp;scene);
    view.show();

    view.scale(2,2);

    return app.exec();
}
</code></pre>
<p dir="auto">The behaviour is the same with the build in QGraphicsOpcityEffect</p>
]]></description><link>https://forum.qt.io/post/396764</link><guid isPermaLink="true">https://forum.qt.io/post/396764</guid><dc:creator><![CDATA[yonnak]]></dc:creator><pubDate>Thu, 01 Jun 2017 10:58:12 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicsEffect and sourcePixmap() on Wed, 31 May 2017 22:00:23 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Can you share your code ?</p>
]]></description><link>https://forum.qt.io/post/396590</link><guid isPermaLink="true">https://forum.qt.io/post/396590</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 31 May 2017 22:00:23 GMT</pubDate></item></channel></rss>