From 54d7c591b5ef0b71882e5132587dbb80769fffae Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Sun, 7 Feb 2021 07:14:24 +0800 Subject: [PATCH] PyQt6 6.0.1 changes QImage constructor api --- pyqtgraph/functions.py | 24 ++++++++++++++---------- pyqtgraph/widgets/RemoteGraphicsView.py | 12 ++++++++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index c53d8cc9..321c9d6b 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -1298,18 +1298,22 @@ def makeQImage(imgData, alpha=None, copy=True, transpose=True): # If the const constructor is used, subsequently calling any non-const method # will trigger the COW mechanism, i.e. a copy is made under the hood. - if QT_LIB == 'PyQt5': - # PyQt5 -> non-const constructor - img_ptr = imgData.ctypes.data - elif QT_LIB == 'PyQt6': - # PyQt5 -> const constructor - # PyQt6 -> non-const constructor - img_ptr = Qt.sip.voidptr(imgData) + if QT_LIB.startswith('PyQt'): + if QtCore.PYQT_VERSION == 0x60000: + # PyQt5 -> const + # PyQt6 >= 6.0.1 -> const + # PyQt6 == 6.0.0 -> non-const + img_ptr = Qt.sip.voidptr(imgData) + else: + # PyQt5 -> non-const + # PyQt6 >= 6.0.1 -> non-const + img_ptr = int(Qt.sip.voidptr(imgData)) # or imgData.ctypes.data else: # bindings that support ndarray - # PyQt5 -> const constructor - # PySide2 -> non-const constructor - # PySide6 -> non-const constructor + # PyQt5 -> const + # PyQt6 >= 6.0.1 -> const + # PySide2 -> non-const + # PySide6 -> non-const img_ptr = imgData img = QtGui.QImage(img_ptr, imgData.shape[1], imgData.shape[0], imgFormat) diff --git a/pyqtgraph/widgets/RemoteGraphicsView.py b/pyqtgraph/widgets/RemoteGraphicsView.py index 68af64f5..119604c4 100644 --- a/pyqtgraph/widgets/RemoteGraphicsView.py +++ b/pyqtgraph/widgets/RemoteGraphicsView.py @@ -228,10 +228,14 @@ class Renderer(GraphicsView): self.shm.resize(size) ## render the scene directly to shared memory - if QT_LIB == 'PyQt5': - img_ptr = int(sip.voidptr(self.shm)) - elif QT_LIB == 'PyQt6': - img_ptr = sip.voidptr(self.shm) + + # see functions.py::makeQImage() for rationale + if QT_LIB.startswith('PyQt'): + if QtCore.PYQT_VERSION == 0x60000: + img_ptr = sip.voidptr(self.shm) + else: + # PyQt5, PyQt6 >= 6.0.1 + img_ptr = int(sip.voidptr(self.shm)) else: # PySide2, PySide6 img_ptr = self.shm