title: Qt: Resizing a png image on Mouse Move Event does not work when resized from left or top side of the rect
body: <p>I have a png image which is displayed on the graphics scene as a QGraphicsPixmapItem.
   The image is rectangular in shape. I need to resize the png image every time it is dragged by a mouse move event on any side of the rectangle ie, from left,right,top or bottom.</p>
  
  <p>Currently I am able to resize the image only when dragged from right and bottom sides only. Image resizing fails when dragged from left and top side. Please let me know the mistakes in my code below. Here Resizing is based on original image file which is of maximum size, but the initial image displayed on the scene itself is a scaled down version of source image. </p>
  
  <p>The partial code is posted below, I have not shown hoverEnterEvent() implementation: </p>
  
  <pre><code>  PersonSizeGraphicsItem::PersonSizeGraphicsItem(const QPixmap &amp;pixmap, QGraphicsScene *scene)
          :QGraphicsPixmapItem(pixmap, 0, scene)
      {
          this-&gt;setFlag(QGraphicsItem::ItemIsMovable, true);
          this-&gt;setFlag(QGraphicsItem::ItemIsSelectable, true);
          this-&gt;setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
          this-&gt;setFlag(QGraphicsItem::ItemIsFocusable, true);
          this-&gt;setFocus(Qt::MouseFocusReason);
          this-&gt;setAcceptHoverEvents(true);
          //this-&gt;setScale(0.5);
  
          rect_left_condition = false;
          rect_right_condition = false;
          rect_top_condition = false;
          rect_bottom_condition = false;
          rect_resize_occurred = false;
          image_rect = QRect();
          image_rect =  this-&gt;pixmap().toImage().rect();
      }
  
      PersonSizeGraphicsItem::~PersonSizeGraphicsItem()
      {
  
      }
  
      int PersonSizeGraphicsItem::type() const
      {
          return item_type;
      }
  
      void PersonSizeGraphicsItem::setSourceImage(const QImage&amp; source_image)
      {
          this-&gt;source_image =  source_image;
      } 
  
      void PersonSizeGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
      {
          const QPointF event_pos = event-&gt;pos();
          const QPointF event_scene_pos = event-&gt;scenePos();
  
              QPoint current_top_left = image_rect.topLeft();
          QPoint current_bottom_right = image_rect.bottomRight();
  
          if((event-&gt;scenePos().x() &gt; this-&gt;scene()-&gt;width()) || (event-&gt;scenePos().y() &gt; this-&gt;scene()-&gt;height())
              || (event-&gt;scenePos().x() &lt; 0) || (event-&gt;scenePos().y() &lt; 0) )
          {
              return;
          }
  
          if( this-&gt;cursor().shape() == Qt::SizeHorCursor )
          {
              if(rect_right_condition)
              {
  
                  image_rect = QRect( current_top_left, QPoint( event-&gt;pos().x(), current_bottom_right.y()) );
  
  
                  rect_resize_occurred = true;
              }
  
              if(rect_left_condition)
              {
                  image_rect = QRect( QPoint(event_pos.x(), 0), current_bottom_right );
  
                  QPoint new_top_left = image_rect.topLeft();
                  QPointF mapped_topLeft = mapToParent(QPointF(new_top_left.x(),new_top_left.y()));
                  this-&gt;setPos(mapped_topLeft);
                  rect_resize_occurred = true;
  
                  //qDebug() &lt;&lt; "new rectangle top left:" &lt;&lt; this-&gt;pixmap().rect().topLeft();
              }
  
          }
  
          if( this-&gt;cursor().shape() == Qt::SizeVerCursor )
          {
              if(rect_bottom_condition)
              {
                  image_rect = QRect(current_top_left, QPoint(current_bottom_right.x(), event-&gt;pos().y()));
  
  
                  rect_resize_occurred = true;
              }
  
              if(rect_top_condition)
              {
                  image_rect = QRect(QPoint(0, event_pos.y()), current_bottom_right);
  
                  QPoint new_top_left = image_rect.topLeft();
                  QPointF mapped_topLeft = mapToParent(QPointF(new_top_left.x(),new_top_left.y()));
                  this-&gt;setPos(mapped_topLeft);
  
                  qDebug() &lt;&lt; "new rectangle top left###:" &lt;&lt; this-&gt;pixmap().rect().topLeft();
                  rect_resize_occurred = true;
  
              }
          }
  
          this-&gt;update();
  
      }
  
  
      void PersonSizeGraphicsItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
      {
          painter-&gt;drawImage(image_rect, source_image);
      }
  
  
  
       QRectF PersonSizeGraphicsItem:: boundingRect() const
       {
          qreal extra = 0.0;
  
            QRect rect = image_rect;
            return QRectF(rect.topLeft(), QSizeF(rect.width(), rect.height()))
              .normalized()
              .adjusted(-extra, -extra, extra, extra);
       }
  </code></pre>