@@ -48,30 +48,31 @@ def paintEvent(self, event):
48
48
right = left + width
49
49
# create a buffer using the image bounding box
50
50
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 ))
54
52
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 )
57
59
58
60
if QT_API == "PyQt6" :
59
61
from PyQt6 import sip
60
62
ptr = int (sip .voidptr (buf ))
61
63
else :
62
64
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 )
66
68
_setDevicePixelRatio (qimage , self .device_pixel_ratio )
67
69
# set origin using original QT coordinates
68
70
origin = QtCore .QPoint (rect .left (), rect .top ())
69
71
painter .drawImage (origin , qimage )
70
72
# Adjust the buf reference count to work around a memory
71
73
# 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
75
76
76
77
self ._draw_rect_callback (painter )
77
78
finally :
0 commit comments