title: Qt :: QGraphicsPixmapItem : overriding paint() method?
body: <p>I want to override QGraphicsPixmapItem that can show an Image and can draw using QPainter on the same item.</p>
  
  <p>I have overridden the class and mouse event and paint methods.When ever i click button it successfully calls mouse and paint events but it does not paint on the image pixmap. </p>
  
  <p>I load image to this item object using setPixmap function 
  i.e.</p>
  
  <pre><code>QGraphicsSelectionPixmapItem selectionitem;
  selectionitem-&gt;setPixmap(imagePixmap); 
  </code></pre>
  
  <p>This is my overridden class:</p>
  
  <h3>Header File: qgraphicsselectionpixmapitem.h</h3>
  
  <pre><code>#ifndef QGRAPHICSSELECTIONPIXMAPITEM_H
  #define QGRAPHICSSELECTIONPIXMAPITEM_H
  #include &lt;QGraphicsPixmapItem&gt;
  #include &lt;QDebug&gt;
  #include &lt;QGraphicsSceneMouseEvent&gt;
  #include &lt;QList&gt;
  #include &lt;QVector&gt;
  #include &lt;QPainter&gt;
  #include &lt;QPixmap&gt;
  
  class QGraphicsSelectionPixmapItem : public QGraphicsPixmapItem
  {
  public:
      QGraphicsSelectionPixmapItem(QGraphicsItem *parent = NULL);
      void mouseMoveEvent(QGraphicsSceneMouseEvent *e);
      void mousePressEvent(QGraphicsSceneMouseEvent *e);
      void mouseReleaseEvent(QGraphicsSceneMouseEvent *e);
      void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
      QList&lt;QPointF&gt; points;
      QVector&lt;QPointF&gt; polyPoints;
      bool mClickflag;
  };
  
  #endif // QGRAPHICSSELECTIONPIXMAPITEM_H
  </code></pre>
  
  <h3>cpp File : qgraphicsselectionpixmapitem.cpp</h3>
  
  <pre><code>#include "qgraphicsselectionpixmapitem.h"
  QGraphicsSelectionPixmapItem::QGraphicsSelectionPixmapItem(QGraphicsItem *parent): QGraphicsPixmapItem(parent)
  {
  }
  
  void QGraphicsSelectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
  {
      mClickflag = true;
      qDebug()&lt;&lt;e-&gt;pos();
      if(e-&gt;lastPos()!=e-&gt;pos()){
          points.append(e-&gt;pos());
          polyPoints&lt;&lt;e-&gt;pos();
          update();
      }
  }
  
  void QGraphicsSelectionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
  {
  }
  
  void QGraphicsSelectionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
  {
       mClickflag = false;
  }
  
  void QGraphicsSelectionPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  {
      qDebug()&lt;&lt;"in Paint ";
      if(!polyPoints.empty())
      {
          painter-&gt;setPen(QPen(QColor(255,0,0),3));
          painter-&gt;drawPolyline(polyPoints);
      }
      QGraphicsPixmapItem::paint(painter,option,widget);
  }
  </code></pre>