title: Qt Update Pixmap of QGraphicsPixmapItem
body: <p>I am using the QGraphicsPixmapItem to show an image on the display. Now, I want to be able to update this image on the fly, but I seem to be running into some issues.</p>
  
  <p>This is the <strong>header</strong> file:</p>
  
  <pre><code>class Enemy_View : public QGraphicsPixmapItem
  {
  public:
      Enemy_View(QGraphicsScene &amp;myScene);
      void defeat();
  private:
      QGraphicsScene &amp;scene;
      QPixmap image;
  }
  </code></pre>
  
  <p>And here is the <strong>cpp</strong> file</p>
  
  <pre><code>Enemy_View::Enemy_View(QGraphicsScene &amp;myScene):
      image{":/images/alive.png"}, scene(myScene)
  {
      QGraphicsPixmapItem *enemyImage = scene.addPixmap(image.scaledToWidth(20));
      enemyImage-&gt;setPos(20, 20);
      this-&gt;defeat();
  }
  
  void Enemy_View::defeat(void)
  {
      image.load(":/images/dead.png");
      this-&gt;setPixmap(image);
      this-&gt;update();
  }
  </code></pre>
  
  <p>SO the idea is that I want to be able to call the <code>defeat</code> method on my object, that then edits some attributes and eventually changes the image. However, what I am doing now does not work. The <code>alive.png</code> image does display, but does not get updated to the <code>dead.png</code> one.</p>
  
  <hr/>
  
  <h1>Update 1</h1>
  
  <p>As mentioned by Marek R I appear to be replicating a lot of built-in functionality. I tried to clean this up but now nothing is showing up on the scene anymore.</p>
  
  <p><strong>.h</strong> file</p>
  
  <pre><code>class Enemy_View : public QGraphicsPixmapItem
  {
  public:
      Enemy_View(QGraphicsScene &amp;myScene);
      void defeat();
  
  private:
      QGraphicsScene &amp;scene;
      /* Extra vars */
  };
  </code></pre>
  
  <p><strong>.cpp</strong> file</p>
  
  <pre><code>Enemy_View::Enemy_View(QGraphicsScene &amp;myScene):
      scene(myScene)
  {
      /* This part would seem ideal but doesn't work */
      this-&gt;setPixmap(QPixmap(":/images/alive.png").scaledToWidth(10));
      this-&gt;setPos(10, 10);
      scene.addItem(this);
  
      /* This part does render the images */
      auto *thisEl = scene.addPixmap(QPixmap(":/images/Jackskellington.png").scaledToWidth(10));
      thisEl-&gt;setPos(10, 10);
      scene.addItem(this);
  
      this-&gt;defeat();
  }
  
  void Enemy_View::defeat(void)
  {
      this-&gt;setPixmap(QPixmap(":/images/dead.png"));
  }
  </code></pre>
  
  <p>So I removed the <code>QPixmap</code>, but I'm not sure whether I can remove the <code>QGraphicsScene</code>. In my <code>cpp</code>-file you can see I have two versions of the constructor now. The first part, using the <code>this</code> seems like an ideal solution, but does not display the image on the screen (even though it does compile without errors). The second version with <code>thisEl</code> does render it. What am I doing wrong with the first version?</p>