Skip to content

Commit 0966b7b

Browse files
committed
Qt5: use qimage2ndarray.array2qimage() for creating a QImage as this supports PythonQt.
1 parent 8b8be5a commit 0966b7b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import ctypes
66

7+
from qimage2ndarray import array2qimage
8+
79
from matplotlib.transforms import Bbox
810

911
from .. import cbook
@@ -52,14 +54,15 @@ def paintEvent(self, event):
5254
buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(
5355
memoryview(reg))
5456

55-
# clear the widget canvas
56-
painter.eraseRect(rect)
57-
58-
qimage = QtGui.QImage(buf, buf.shape[1], buf.shape[0],
59-
QtGui.QImage.Format_ARGB32_Premultiplied)
57+
# create a QImage from the array buffer
58+
qimage = array2qimage(buf)
6059
if hasattr(qimage, 'setDevicePixelRatio'):
6160
# Not available on Qt4 or some older Qt5.
6261
qimage.setDevicePixelRatio(self._dpi_ratio)
62+
63+
# clear the widget canvas
64+
painter.eraseRect(rect)
65+
6366
origin = QtCore.QPoint(left, top)
6467
painter.drawImage(origin / self._dpi_ratio, qimage)
6568
# Adjust the buf reference count to work around a memory

0 commit comments

Comments
 (0)