'How PyQt5 implements cropping images by mouse frame
I need to crop a image.
The image is displayed on the Qlabel, and I have prepared the button to start cropping and the button to save the cropped image.
The goal is that after pressing the crop button, pressing and releasing the mouse can draw a frame on the original image, frame the area I want, and display it, and finally save the cropped image locally through the save image button. And I have multiple images that need to be cropped, they are saved in each page of Qgroupbox.
This is my qt interface diagram:

Here is part of my code:
self.labels_cut5678 = [self.label_cutphoto5, self.label_cutphoto6, self.label_cutphoto7, self.label_cutphoto8]
self.pushButton_cut.clicked.connect(self.pushButton_cut_clicked)
self.pushButton_save.clicked.connect(self.pushButton_save_clicked)
...
def photoload_right(self):
"""加载右目图像,4张"""
imgName, imgType = QFileDialog.getOpenFileNames(self.centralwidget, "打开图片", "", "*.jpg;;*.png;;All Files(*)")
# 弹出一个文件选择框,第一个返回值imgName记录选中的文件路径+文件名,第二个返回值imgType记录文件的类型
for i in range(len(imgName)):
jpg_cut = QtGui.QPixmap(imgName[i]).scaled(self.labels_cut5678[i].size(), Qt.KeepAspectRatio)
self.labels_cut5678[i].setPixmap(jpg_cut)
# self.labels_cut5678[i].repaint()
self.labels_cut5678[i].adjustSize()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
