<?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[QGraphicsPixmapItem not showing when added to scene]]></title><description><![CDATA[<p dir="auto">My understanding is as follows:</p>
<p dir="auto">I create a QGraphicsView, QGraphicsScene, and QPixmap.<br />
The resource file allows me to customize the string for the file location. In this case, it's set to ":/piece/b_bishop.png" according to the documentation for resource files.<br />
I create a QGraphicsPixmapItem using the QPixmap I created earlier.<br />
I set the QGraphicsPixmapItem to the QGraphicsScene.<br />
I set the scene to the view.<br />
I show the view, but nothing happens.<br />
Just to make sure, I changed the background color.</p>
<p dir="auto">Below, I have my code.</p>
<pre><code>#include &lt;QApplication&gt;
#include &lt;QGraphicsScene&gt;
#include &lt;QGraphicsView&gt;
#include &lt;QGraphicsPixmapItem&gt;
#include &lt;QPixmap&gt;
int main(int argc, char **argv)
{
    QApplication app (argc, argv);
    QGraphicsView view;
    QGraphicsScene scene;
    scene.setBackgroundBrush(Qt::green);
    
    QPixmap map (":/piece/b_bishop.png");
    QGraphicsPixmapItem bishop(map);
    scene.addItem(&amp;bishop);

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

    return app.exec();
}
</code></pre>
<pre><code>&lt;RCC&gt;
    &lt;qresource prefix="/piece"&gt;
        &lt;file&gt;chesspieces/b_bishop.png&lt;/file&gt;
    &lt;/qresource&gt;
&lt;/RCC&gt;
</code></pre>
<p dir="auto">The image, as shown in the QT Creator:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/b0345cac-0d71-4518-b83d-c638fef54462.png" alt="1174bd28-43cb-422d-883b-8168344e3c78-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">I've currently tried: adjusting the syntax in multiple ways. By everything I have seen, I have done this correctly. I must be missing something. Thanks for your help.</p>
]]></description><link>https://forum.qt.io/topic/135443/qgraphicspixmapitem-not-showing-when-added-to-scene</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Jul 2026 08:41:45 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/135443.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 31 Mar 2022 17:53:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QGraphicsPixmapItem not showing when added to scene on Thu, 31 Mar 2022 17:55:26 GMT]]></title><description><![CDATA[<p dir="auto">Shouldn't it be</p>
<blockquote>
<p dir="auto">/piece/hesspieces/b_bishop.png</p>
</blockquote>
<p dir="auto">?<br />
Please check with QFile::exists() if your path is really correct.</p>
]]></description><link>https://forum.qt.io/post/708450</link><guid isPermaLink="true">https://forum.qt.io/post/708450</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Thu, 31 Mar 2022 17:55:26 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicsPixmapItem not showing when added to scene on Thu, 31 Mar 2022 18:47:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a></p>
<p dir="auto">I'm real dumb, I figured it out. Your solution worked, just had to keep digging. I had mixed up file names apparently.</p>
]]></description><link>https://forum.qt.io/post/708462</link><guid isPermaLink="true">https://forum.qt.io/post/708462</guid><dc:creator><![CDATA[SlappyDanger]]></dc:creator><pubDate>Thu, 31 Mar 2022 18:47:14 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicsPixmapItem not showing when added to scene on Thu, 31 Mar 2022 18:43:21 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Maybe a silly question but did you list your .qrc file in your .pro file ?</p>
]]></description><link>https://forum.qt.io/post/708461</link><guid isPermaLink="true">https://forum.qt.io/post/708461</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 31 Mar 2022 18:43:21 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicsPixmapItem not showing when added to scene on Thu, 31 Mar 2022 18:37:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a></p>
<p dir="auto">absolute path works.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/07921c59-d0e4-4b58-9e87-3d0b1b35102d.png" alt="5c8d8acb-6a29-4260-9344-dfe2c25deff2-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">I would much prefer not having to use absolute paths, though</p>
]]></description><link>https://forum.qt.io/post/708458</link><guid isPermaLink="true">https://forum.qt.io/post/708458</guid><dc:creator><![CDATA[SlappyDanger]]></dc:creator><pubDate>Thu, 31 Mar 2022 18:37:18 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicsPixmapItem not showing when added to scene on Thu, 31 Mar 2022 18:15:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a></p>
<p dir="auto">Honestly I have no idea what that is, so probably not.</p>
<p dir="auto">I just tried.</p>
<p dir="auto">"QWidget: Cannot create a QWidget without QApplication"</p>
]]></description><link>https://forum.qt.io/post/708455</link><guid isPermaLink="true">https://forum.qt.io/post/708455</guid><dc:creator><![CDATA[SlappyDanger]]></dc:creator><pubDate>Thu, 31 Mar 2022 18:15:26 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicsPixmapItem not showing when added to scene on Thu, 31 Mar 2022 18:09:23 GMT]]></title><description><![CDATA[<p dir="auto">Did you instantiate a Q(Core)Application before your test?</p>
]]></description><link>https://forum.qt.io/post/708454</link><guid isPermaLink="true">https://forum.qt.io/post/708454</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Thu, 31 Mar 2022 18:09:23 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicsPixmapItem not showing when added to scene on Thu, 31 Mar 2022 18:07:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a></p>
<p dir="auto">I took your advice, and tried these:</p>
<pre><code>QFile file1(":/piece/chesspieces/b_bishop.png");
QFile file2(":/piece/b_bishop.png");
QFile file3(":/chesspieces/b_bishop.png");

if(file1.exists())
    qDebug() &lt;&lt; "file 1 exists";
else
    qDebug() &lt;&lt; "file 1 does not exist";
if(file2.exists())
    qDebug() &lt;&lt; "file 2 exists";
else
    qDebug() &lt;&lt; "file 2 does not exist";
if(file3.exists())
    qDebug() &lt;&lt; "file 3 exists";
else
    qDebug() &lt;&lt; "file 3 does not exist";
</code></pre>
<p dir="auto">None of them exist, assuming I wrote that code correctly to check lol.</p>
<p dir="auto">Here is my file location:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/e036ccda-d473-477e-b5cb-31414d8ca22f.png" alt="36dd1713-b1d5-4d69-9303-0819a4ff4c43-image.png" class=" img-fluid img-markdown" /><br />
<img src="https://ddgobkiprc33d.cloudfront.net/94517a9e-ae24-426f-b6f0-ce97dec865c5.png" alt="0d64aafd-5070-4074-bb9c-564336f892d8-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Ignore the other files, i'm just using main to test this.</p>
<p dir="auto">I'm creating the resource file with the QT Creator, and adding files to it the same way.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/1148bd61-574f-4bba-b8ef-fd3faf6fb644.png" alt="f6a5be2f-d5f6-4baa-b179-71cdc3434c8e-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/708452</link><guid isPermaLink="true">https://forum.qt.io/post/708452</guid><dc:creator><![CDATA[SlappyDanger]]></dc:creator><pubDate>Thu, 31 Mar 2022 18:07:34 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicsPixmapItem not showing when added to scene on Thu, 31 Mar 2022 17:55:26 GMT]]></title><description><![CDATA[<p dir="auto">Shouldn't it be</p>
<blockquote>
<p dir="auto">/piece/hesspieces/b_bishop.png</p>
</blockquote>
<p dir="auto">?<br />
Please check with QFile::exists() if your path is really correct.</p>
]]></description><link>https://forum.qt.io/post/708450</link><guid isPermaLink="true">https://forum.qt.io/post/708450</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Thu, 31 Mar 2022 17:55:26 GMT</pubDate></item></channel></rss>