From 6e2a28260acbef3da83f55af6287d0a3a5bc6899 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Mon, 11 Jan 2021 15:27:04 +0800 Subject: [PATCH] add QImage support for PySide6 also update for PySide2.QImage to take in ndarray directly. --- pyqtgraph/functions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 5cafae16..32fb9626 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -1260,9 +1260,11 @@ def makeQImage(imgData, alpha=None, copy=True, transpose=True): if copy is True and copied is False: imgData = imgData.copy() - if QT_LIB in ['PySide', 'PySide2']: + if QT_LIB == 'PySide': ch = ctypes.c_char.from_buffer(imgData, 0) img = QtGui.QImage(ch, imgData.shape[1], imgData.shape[0], imgFormat) + elif QT_LIB in ['PySide2', 'PySide6']: + img = QtGui.QImage(imgData, imgData.shape[1], imgData.shape[0], imgFormat) else: ## PyQt API for QImage changed between 4.9.3 and 4.9.6 (I don't know exactly which version it was) ## So we first attempt the 4.9.6 API, then fall back to 4.9.3 @@ -1288,7 +1290,7 @@ def imageToArray(img, copy=False, transpose=True): """ fmt = img.format() ptr = img.bits() - if QT_LIB in ['PySide', 'PySide2']: + if QT_LIB in ['PySide', 'PySide2', 'PySide6']: arr = np.frombuffer(ptr, dtype=np.ubyte) else: ptr.setsize(img.byteCount())