From d4128be847b08c3d95c8878c224973787bbc1cf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:38:28 +0800 Subject: [PATCH] . --- .../LunaTranslator/gui/showocrimage.py | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/showocrimage.py b/LunaTranslator/LunaTranslator/gui/showocrimage.py index dd2819ba..8085e341 100644 --- a/LunaTranslator/LunaTranslator/gui/showocrimage.py +++ b/LunaTranslator/LunaTranslator/gui/showocrimage.py @@ -6,6 +6,33 @@ from myutils.wrapper import Singleton_close from gui.usefulwidget import saveposwindow +class pixlabel(QLabel): + def __init__(self): + super().__init__() + self.pix = None + + def setpix(self, pix): + self.pix = pix + self.setPixmap( + self.pix.scaled( + self.size(), + Qt.AspectRatioMode.KeepAspectRatio, + Qt.TransformationMode.SmoothTransformation, + ) + ) + + def resizeEvent(self, a0): + if self.pix: + self.setPixmap( + self.pix.scaled( + self.size(), + Qt.AspectRatioMode.KeepAspectRatio, + Qt.TransformationMode.SmoothTransformation, + ) + ) + return super().resizeEvent(a0) + + @Singleton_close class showocrimage(saveposwindow): setimage = pyqtSignal(list) @@ -20,9 +47,9 @@ class showocrimage(saveposwindow): super().__init__(parent, globalconfig, "showocrgeo") self.setWindowIcon(qtawesome.icon("fa.picture-o")) self.setWindowTitle(_TR("查看处理效果")) - self.originlabel = QLabel(self) + self.originlabel = pixlabel() qw = QWidget() - self.solvedlabel = QLabel(self) + self.solvedlabel = pixlabel() self.lay2 = QHBoxLayout() button = QPushButton( icon=qtawesome.icon("fa.rotate-right", color=globalconfig["buttoncolor"]) @@ -46,28 +73,6 @@ class showocrimage(saveposwindow): img = imagesolve(self.originimage) self.setimagefunction([self.originimage, img]) - def showimg(self): - - self.originlabel.setPixmap( - self.img1.scaled( - self.originlabel.size(), - Qt.AspectRatioMode.KeepAspectRatio, - Qt.TransformationMode.SmoothTransformation, - ) - ) - self.solvedlabel.setPixmap( - self.img2.scaled( - self.solvedlabel.size(), - Qt.AspectRatioMode.KeepAspectRatio, - Qt.TransformationMode.SmoothTransformation, - ) - ) - - def resizeEvent(self, a0) -> None: - if self.img1 is not None: - self.showimg() - return super().resizeEvent(a0) - def setimagefunction(self, image): originimage, solved = image self.originimage = originimage @@ -75,4 +80,5 @@ class showocrimage(saveposwindow): self.img2 = QPixmap.fromImage(solved) self.img1.setDevicePixelRatio(self.devicePixelRatioF()) self.img2.setDevicePixelRatio(self.devicePixelRatioF()) - self.showimg() + self.originlabel.setpix(self.img1) + self.solvedlabel.setpix(self.img2)