@@ -240,8 +240,7 @@ def qcontrol(self, name_or_id: str | int):
240240
241241
242242class QVideoStream (QtCore .QObject ):
243- qpixmap = None
244- pixmapChanged = QtCore .Signal (object )
243+ imageChanged = QtCore .Signal (object )
245244
246245 def __init__ (self , camera : QCamera | None = None ):
247246 super ().__init__ ()
@@ -250,10 +249,7 @@ def __init__(self, camera: QCamera | None = None):
250249
251250 def on_frame (self , frame ):
252251 qimage = frame .user_data or frame_to_qimage (frame )
253- if self .qpixmap is None :
254- self .qpixmap = QtGui .QPixmap ()
255- self .qpixmap .convertFromImage (qimage )
256- self .pixmapChanged .emit (self .qpixmap )
252+ self .imageChanged .emit (qimage )
257253
258254 def set_camera (self , camera : QCamera | None = None ):
259255 if self .camera :
@@ -852,33 +848,33 @@ def set_camera(self, camera: QCamera | None = None):
852848 self .camera = camera
853849
854850
855- def paint_pixmap (painter , width , height , qpixmap = None ):
856- if qpixmap is None :
851+ def paint_image (painter , width , height , qimage = None ):
852+ if qimage is None :
857853 draw_no_image (painter , width , height )
858854 return
859- image_width = qpixmap .width ()
860- image_height = qpixmap .height ()
855+ image_width = qimage .width ()
856+ image_height = qimage .height ()
861857 scale = min (width / image_width , height / image_height )
862858 rect_width = int (image_width * scale )
863859 rect_height = int (image_height * scale )
864860 x = int ((width - rect_width ) / 2 )
865861 y = int ((height - rect_height ) / 2 )
866862 rect = QtCore .QRect (x , y , rect_width , rect_height )
867- painter .drawPixmap (rect , qpixmap )
863+ painter .drawImage (rect , qimage )
868864
869865
870866class VideoMixin :
871- qpixmap = None
867+ qimage = None
872868
873869 def imageRect (self ):
874870 return self .rect ()
875871
876872 def paint (self , painter , _ , * args ):
877873 rect = self .imageRect ()
878- paint_pixmap (painter , rect .width (), rect .height (), self .qpixmap )
874+ paint_image (painter , rect .width (), rect .height (), self .qimage )
879875
880876 def on_pixmap_changed (self , qpixmap ):
881- self .qpixmap = qpixmap
877+ self .qimage = qpixmap
882878 self .update ()
883879
884880
@@ -893,8 +889,8 @@ def minimumSizeHint(self):
893889class QVideoItem (VideoMixin , QtWidgets .QGraphicsItem ):
894890 def boundingRect (self ):
895891 width , height = 640 , 480
896- if self .qpixmap :
897- width , height = self .qpixmap .width (), self .qpixmap .height ()
892+ if self .qimage :
893+ width , height = self .qimage .width (), self .qimage .height ()
898894 return QtCore .QRectF (0 , 0 , width , height )
899895
900896 imageRect = boundingRect
@@ -906,7 +902,7 @@ def __init__(self, camera=None):
906902 layout = QtWidgets .QVBoxLayout (self )
907903 self .video = QVideo ()
908904 self .stream = QVideoStream (camera )
909- self .stream .pixmapChanged .connect (self .video .on_pixmap_changed )
905+ self .stream .imageChanged .connect (self .video .on_pixmap_changed )
910906 self .controls = QVideoControls (camera )
911907 layout .addWidget (self .video )
912908 layout .addWidget (self .controls )
0 commit comments