title: Cropping a QImage using Mouse Events in Qt
body: <p>I need to crop a QImage displayed on a QLabel. I want to do it with mouseevents like dragging a rectangle on the image and then on the releaseevent the image should crop to the size of the rectangle. I have implemented this code:</p>
  
  <pre><code>void surf_detection::mousePressEvent(QMouseEvent *ev)
  {
  if(ui-&gt;label_2-&gt;underMouse()){
      cout &lt;&lt;"Entered Press"&lt;&lt;endl;
      origin = ev-&gt;pos();
      //if (!rubberBand)
          rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
  
          rubberBand-&gt;show();
  }
  }
  
  void surf_detection::mouseMoveEvent(QMouseEvent *ev)
  {
  
  rubberBand-&gt;setGeometry(QRect(origin, ev-&gt;pos()).normalized());                                                                                                              
  }
  
  void surf_detection::mouseReleaseEvent(QMouseEvent *ev)
  {
  QPoint a = mapToGlobal(origin);
  QPoint b = ev-&gt;globalPos();
  
  a = ui-&gt;label_2-&gt;mapFromGlobal(a);
  b = ui-&gt;label_2-&gt;mapFromGlobal(b);
  rubberBand-&gt;hide();
  QPixmap OriginalPix(*ui-&gt;label_2-&gt;pixmap());
  double sx = ui-&gt;label_2-&gt;rect().width();
  double sy = ui-&gt;label_2-&gt;rect().height();
  sx = OriginalPix.width() / sx;
  sy = OriginalPix.height() / sy;
  
  a.x = int(a.x * sx);
  b.x = int(b.x * sx);
  a.y = int(a.y * sy);
  b.y = int(b.y * sy);
  
  QRect myRect(a,b);
  
  QImage newImage;
  newImage = OriginalPix.toImage();
  
  QImage copyImage;
  copyImage = copyImage.copy(myRect);
  
  ui-&gt;label_2-&gt;setPixmap(QPixmap::fromImage(copyImage));
  ui-&gt;label_2-&gt;repaint();
  
  }
  </code></pre>
  
  <p>But this code gives me error at </p>
  
  <pre><code>a.x = int(a.x * sx);
  b.x = int(b.x * sx);
  a.y = int(a.y * sy);
  b.y = int(b.y * sy);
  </code></pre>
  
  <p>error: invalid use of member function (did you forget the '()' ?)</p>
  
  <p>a.x = int(a.x * sx);
                    ^</p>
  
  <p>How do i resolve this? </p>