@@ -48,30 +48,31 @@ def paintEvent(self, event):
4848 right = left + width
4949 # create a buffer using the image bounding box
5050 bbox = Bbox ([[left , bottom ], [right , top ]])
51- reg = self .copy_from_bbox (bbox )
52- buf = cbook ._unmultiplied_rgba8888_to_premultiplied_argb32 (
53- memoryview (reg ))
51+ buf = memoryview (self .copy_from_bbox (bbox ))
5452
55- # clear the widget canvas
56- painter .eraseRect (rect )
53+ fmts = _enum ("QtGui.QImage.Format" )
54+ if hasattr (fmts , "Format_RGBA8888" ):
55+ fmt = fmts .Format_RGBA8888
56+ else : # Qt<=5.1 support.
57+ fmt = fmts .Format_ARGB32_Premultiplied
58+ buf = cbook ._unmultiplied_rgba8888_to_premultiplied_argb32 (buf )
5759
5860 if QT_API == "PyQt6" :
5961 from PyQt6 import sip
6062 ptr = int (sip .voidptr (buf ))
6163 else :
6264 ptr = buf
63- qimage = QtGui . QImage (
64- ptr , buf . shape [ 1 ], buf . shape [ 0 ],
65- _enum ( " QtGui.QImage.Format" ). Format_ARGB32_Premultiplied )
65+
66+ painter . eraseRect ( rect ) # clear the widget canvas
67+ qimage = QtGui .QImage ( ptr , buf . shape [ 1 ], buf . shape [ 0 ], fmt )
6668 _setDevicePixelRatio (qimage , self .device_pixel_ratio )
6769 # set origin using original QT coordinates
6870 origin = QtCore .QPoint (rect .left (), rect .top ())
6971 painter .drawImage (origin , qimage )
7072 # Adjust the buf reference count to work around a memory
7173 # leak bug in QImage under PySide.
72- if QT_API in ('PySide' , 'PySide2' ):
73- if QtCore .__version_info__ < (5 , 12 ):
74- ctypes .c_long .from_address (id (buf )).value = 1
74+ if QT_API == "PySide2" and QtCore .__version_info__ < (5 , 12 ):
75+ ctypes .c_long .from_address (id (buf )).value = 1
7576
7677 self ._draw_rect_callback (painter )
7778 finally :
0 commit comments