<?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[Refresh QGraphicsView]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I am using a QGraphicsView and a button, in order to load and display images as seems from the following code. But when I have already loaded an image in my QGraphicsView, and I am trying to load an other image, then my new image is displayed on my previous image. What should I change to refresh my QGraphicsView correctly? graphicsView_inputImage is the name of my QGraphicsView and scene is a global pointer to my QGraphicsScene.</p>
<p dir="auto">@ void MainWindow::push_button_File(void)<br />
{</p>
<pre><code> QString fileName = QFileDialog::getOpenFileName(this,
                                 tr("Open File"&amp;#41;, QDir::currentPath());
 if (!fileName.isEmpty()) {
scene-&gt;addPixmap(QPixmap(fileName, 0, Qt::AutoColor));
     ui-&gt;graphicsView_inputImage-&gt;setScene(scene);

 }
</code></pre>
<p dir="auto">return ;<br />
}@</p>
]]></description><link>https://forum.qt.io/topic/6135/refresh-qgraphicsview</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 13:48:54 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/6135.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 May 2011 17:41:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Refresh QGraphicsView on Fri, 09 Mar 2012 13:58:43 GMT]]></title><description><![CDATA[<p dir="auto">following Error Coming in my system..!<br />
QPixmap::operator=: Cannot assign to pixmap during painting.</p>
<p dir="auto">When i was trying to do this code with menubar actions.</p>
<p dir="auto">Please help me out.</p>
]]></description><link>https://forum.qt.io/post/100754</link><guid isPermaLink="true">https://forum.qt.io/post/100754</guid><dc:creator><![CDATA[Aniket]]></dc:creator><pubDate>Fri, 09 Mar 2012 13:58:43 GMT</pubDate></item><item><title><![CDATA[Reply to Refresh QGraphicsView on Wed, 25 May 2011 19:34:00 GMT]]></title><description><![CDATA[<p dir="auto">Ok that was my mistake. Now I am taking the correct results. Thanks a lot for your help!!</p>
]]></description><link>https://forum.qt.io/post/89585</link><guid isPermaLink="true">https://forum.qt.io/post/89585</guid><dc:creator><![CDATA[jk_mk]]></dc:creator><pubDate>Wed, 25 May 2011 19:34:00 GMT</pubDate></item><item><title><![CDATA[Reply to Refresh QGraphicsView on Wed, 25 May 2011 19:28:49 GMT]]></title><description><![CDATA[<p dir="auto">The first thing you tried is not what I suggested. Remove the "new QGraphicsPixmapItem()"</p>
]]></description><link>https://forum.qt.io/post/89583</link><guid isPermaLink="true">https://forum.qt.io/post/89583</guid><dc:creator><![CDATA[baysmith]]></dc:creator><pubDate>Wed, 25 May 2011 19:28:49 GMT</pubDate></item><item><title><![CDATA[Reply to Refresh QGraphicsView on Wed, 25 May 2011 19:26:28 GMT]]></title><description><![CDATA[<p dir="auto">I have tried this and I couldn't display my image in the QGraphicsView at all:</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> MainWindow::push_button_File(void)<br />
{<br />
QGraphicsPixmapItem* pixmapItem = new QGraphicsPixmapItem();<br />
QString fileName = QFileDialog::getOpenFileName(this,<br />
tr("Open File"), QDir::currentPath());<br />
if (!fileName.isEmpty()) {<br />
if (!pixmapItem) {<br />
pixmapItem = scene-&gt;addPixmap(QPixmap(fileName, 0, Qt::AutoColor));<br />
ui-&gt;graphicsView_inputImage-&gt;setScene(scene);<br />
} else {<br />
pixmapItem-&gt;setPixmap(QPixmap(fileName, 0, Qt::AutoColor));<br />
}<br />
}</p>
<pre><code>return;
</code></pre>
<p dir="auto">}@</p>
<p dir="auto">and also I have tried this, but I took the same results (the new image on the previous image)</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> MainWindow::push_button_File(void)<br />
{</p>
<pre><code> QString fileName = QFileDialog::getOpenFileName(this,
                                 tr("Open File"), QDir::currentPath());
 if (!fileName.isEmpty()) {
</code></pre>
<p dir="auto">QGraphicsPixmapItem *pix= new QGraphicsPixmapItem();<br />
pix-&gt;setPixmap(QPixmap(fileName, 0, Qt::AutoColor));<br />
scene-&gt;addItem(pix);<br />
ui-&gt;graphicsView_inputImage-&gt;setScene(scene);<br />
}</p>
<p dir="auto">return ;</p>
<p dir="auto">}@</p>
]]></description><link>https://forum.qt.io/post/89584</link><guid isPermaLink="true">https://forum.qt.io/post/89584</guid><dc:creator><![CDATA[jk_mk]]></dc:creator><pubDate>Wed, 25 May 2011 19:26:28 GMT</pubDate></item><item><title><![CDATA[Reply to Refresh QGraphicsView on Wed, 25 May 2011 19:14:41 GMT]]></title><description><![CDATA[<p dir="auto">Perhaps something like this.<br />
@<br />
void MainWindow::push_button_File(void)<br />
{<br />
static QGraphicsPixmapItem* pixmapItem;<br />
QString fileName = QFileDialog::getOpenFileName(this,<br />
tr("Open File"), QDir::currentPath());<br />
if (!fileName.isEmpty()) {<br />
if (!pixmapItem) {<br />
pixmapItem = scene-&gt;addPixmap(QPixmap(fileName, 0, Qt::AutoColor));<br />
ui-&gt;graphicsView_inputImage-&gt;setScene(scene);<br />
} else {<br />
pixmapItem-&gt;setPixmap(QPixmap(fileName, 0, Qt::AutoColor));<br />
}<br />
}</p>
<pre><code>return;
</code></pre>
<p dir="auto">}<br />
@</p>
]]></description><link>https://forum.qt.io/post/89582</link><guid isPermaLink="true">https://forum.qt.io/post/89582</guid><dc:creator><![CDATA[baysmith]]></dc:creator><pubDate>Wed, 25 May 2011 19:14:41 GMT</pubDate></item><item><title><![CDATA[Reply to Refresh QGraphicsView on Wed, 25 May 2011 18:44:18 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your response. But the scene is member of QGraphicsScene and scene doesn't include the method setPixmap(). How could I set a new pixmap? Could you be more specific?</p>
]]></description><link>https://forum.qt.io/post/89578</link><guid isPermaLink="true">https://forum.qt.io/post/89578</guid><dc:creator><![CDATA[jk_mk]]></dc:creator><pubDate>Wed, 25 May 2011 18:44:18 GMT</pubDate></item><item><title><![CDATA[Reply to Refresh QGraphicsView on Wed, 25 May 2011 18:24:38 GMT]]></title><description><![CDATA[<p dir="auto">Addpixmap is actually a part of QGraphicsPixmapItem , so try to use set pixmap <a href="http://doc.qt.nokia.com/latest/qgraphicspixmapitem.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.nokia.com/latest/qgraphicspixmapitem.html</a></p>
<p dir="auto">As it is clear in your code , you are adding new PixMAP Item to the item and not setting new  or removing old one.</p>
]]></description><link>https://forum.qt.io/post/89577</link><guid isPermaLink="true">https://forum.qt.io/post/89577</guid><dc:creator><![CDATA[Satmosc]]></dc:creator><pubDate>Wed, 25 May 2011 18:24:38 GMT</pubDate></item></channel></rss>