cropping image on QLabel using mouseEvent
- 
@mjjj as u said i hv changed 
 copyImage=newImage.copy(myRect);but here wat happens after dragged image,, its showing QLabel is completely black 
- 
@Dimple 
 the calculations for the actual rect to copya = ui->label->mapFromGlobal(a); b = ui->label->mapFromGlobal(b); double sx = ui->label->rect().width(); double sy = ui->label->rect().height(); sx = OriginalPix.width() / sx; sy = OriginalPix.height() / sy; a.setX(int(a.x() * sx)); b.setX(int(b.x() * sx)); a.setX(int(a.x() * sy)); b.setX(int(b.x() * sy)); QRect myRect(a, b); // im not sure this rect is as intended.try use qDebug to write it out and inspect the values. 
 like
 qDebug() << " crop rect" << myRect;
- 
@Dimple 
 the calculations for the actual rect to copya = ui->label->mapFromGlobal(a); b = ui->label->mapFromGlobal(b); double sx = ui->label->rect().width(); double sy = ui->label->rect().height(); sx = OriginalPix.width() / sx; sy = OriginalPix.height() / sy; a.setX(int(a.x() * sx)); b.setX(int(b.x() * sx)); a.setX(int(a.x() * sy)); b.setX(int(b.x() * sy)); QRect myRect(a, b); // im not sure this rect is as intended.try use qDebug to write it out and inspect the values. 
 like
 qDebug() << " crop rect" << myRect;
- 
a.setX(int(a.x() * sx)); 
 b.setX(int(b.x() * sx));
 a.setY(int(a.y() * sy));
 b.setY(int(b.y() * sy));QRect myRect(a,b); QImage newImage; 
 newImage = OriginalPix.toImage();
 QImage copyImage;
 copyImage=newImage.copy(myRect);
 ui->label->setPixmap(QPixmap::fromImage(copyImage));
 ui->label->setScaledContents(true);
 ui->label->repaint();now its working ,,i can crop the image but after cropped the image ,,,if i click on cropped image ,,image is disappearing? 
- 
a.setX(int(a.x() * sx)); 
 b.setX(int(b.x() * sx));
 a.setY(int(a.y() * sy));
 b.setY(int(b.y() * sy));QRect myRect(a,b); QImage newImage; 
 newImage = OriginalPix.toImage();
 QImage copyImage;
 copyImage=newImage.copy(myRect);
 ui->label->setPixmap(QPixmap::fromImage(copyImage));
 ui->label->setScaledContents(true);
 ui->label->repaint();now its working ,,i can crop the image but after cropped the image ,,,if i click on cropped image ,,image is disappearing? 
- 
@mrjj said in cropping image on QLabel using mouseEvent: triggers ok i ll change some functionality ,,Thanks for ur help 
