Alex Sidorov 1 жил өмнө
parent
commit
0919e4809b

+ 4 - 2
module/cam/IPCam.py

@@ -46,12 +46,14 @@ class IPCam(Thread):
 
                 _, _, ch = color_frame.shape
                 
-                label_geometry = self.qLabel.geometry()
-                h, w = label_geometry.height(), label_geometry.width()
                 
                 img = QImage(color_frame.data, w, h,
                              ch * w, QImage.Format_RGB888)
                 
+                
+                label_geometry = self.qLabel.geometry()
+                h, w = label_geometry.height(), label_geometry.width()
+                
                 self.__scaled_img = QPixmap.fromImage(
                     img.scaled(h, w, Qt.KeepAspectRatio))
 

+ 24 - 2
widgets/PStackedWidget.py

@@ -1,4 +1,6 @@
 from PySide6.QtWidgets import QStackedWidget, QWidget, QLabel, QGridLayout
+from PySide6.QtGui import QResizeEvent, QPixmap
+from PySide6.QtCore import QSize
 from PySide6.QtMultimediaWidgets import QVideoWidget
 from module.cam.USBCam import load_image
 import os
@@ -8,10 +10,30 @@ class PStackedWidget(QStackedWidget):
     def __init__(self, parent=None, mode='video'):
         super(PStackedWidget, self).__init__(parent)
         self.__mode = mode
+        self.resize_state = False
 
         self.__setup_image_stacked()
         self.__setup_video_stacked()
         self.set_default_image()
+        self.resizeEvent = self.__resize
+        
+    def __resize(self, event: QResizeEvent) -> None:
+        self.image.resize(event.size())
+        self.video.resize(event.size())
+        img = self.image.pixmap().toImage().scaled(
+            event.size().width()-20,
+            event.size().height()-20
+        )
+        self.image.setPixmap(QPixmap.fromImage(img))
+        
+        if self.video.__class__.__name__ in 'QLabel':
+            img = self.video.pixmap().toImage().scaled(
+                event.size().width()-20,
+                event.size().height()-20
+            )
+            self.video.setPixmap(QPixmap.fromImage(img))
+        
+        # print(type(self.video))
 
     def __setup_image_stacked(self) -> None:
         self.page_image = QWidget()
@@ -22,7 +44,7 @@ class PStackedWidget(QStackedWidget):
 
         self.image = QLabel(self.page_image)
         self.image.setObjectName("image")
-        self.layout_image.addWidget(self.image, 0, 0, 0, 0)
+        self.layout_image.addWidget(self.image)
 
         self.addWidget(self.page_image)
 
@@ -39,7 +61,7 @@ class PStackedWidget(QStackedWidget):
             self.video = QLabel(self.page_video)
 
         self.video.setObjectName("video")
-        self.layout_video.addWidget(self.video, 0, 0, 0, 0)
+        self.layout_video.addWidget(self.video)
 
         self.addWidget(self.page_video)
 

+ 2 - 1
window/MainWindow.py

@@ -8,7 +8,8 @@ from module.TemplatePropusk import TemplatePropusk
 from module.Printer import Printer
 from module.lang.ru import *
 from module.cam import IPCam, USBCam, load_image
-from module import QRCode, create_path_qr
+import module.QRCode
+from module import create_path_qr
 # from module.ImageTool import cupture_face
 
 from widgets import PStackedWidget, create_widget_stacked