Merge pull request #1553 from pijyoi/pyqt6_qimage_api_change

This commit is contained in:
Ogi Moore 2021-02-06 15:36:04 -08:00 committed by GitHub
commit 4274e33486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 14 deletions

View File

@ -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 # 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. # will trigger the COW mechanism, i.e. a copy is made under the hood.
if QT_LIB == 'PyQt5': if QT_LIB.startswith('PyQt'):
# PyQt5 -> non-const constructor if QtCore.PYQT_VERSION == 0x60000:
img_ptr = imgData.ctypes.data # PyQt5 -> const
elif QT_LIB == 'PyQt6': # PyQt6 >= 6.0.1 -> const
# PyQt5 -> const constructor # PyQt6 == 6.0.0 -> non-const
# PyQt6 -> non-const constructor
img_ptr = Qt.sip.voidptr(imgData) 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: else:
# bindings that support ndarray # bindings that support ndarray
# PyQt5 -> const constructor # PyQt5 -> const
# PySide2 -> non-const constructor # PyQt6 >= 6.0.1 -> const
# PySide6 -> non-const constructor # PySide2 -> non-const
# PySide6 -> non-const
img_ptr = imgData img_ptr = imgData
img = QtGui.QImage(img_ptr, imgData.shape[1], imgData.shape[0], imgFormat) img = QtGui.QImage(img_ptr, imgData.shape[1], imgData.shape[0], imgFormat)

View File

@ -228,10 +228,14 @@ class Renderer(GraphicsView):
self.shm.resize(size) self.shm.resize(size)
## render the scene directly to shared memory ## render the scene directly to shared memory
if QT_LIB == 'PyQt5':
img_ptr = int(sip.voidptr(self.shm)) # see functions.py::makeQImage() for rationale
elif QT_LIB == 'PyQt6': if QT_LIB.startswith('PyQt'):
if QtCore.PYQT_VERSION == 0x60000:
img_ptr = sip.voidptr(self.shm) img_ptr = sip.voidptr(self.shm)
else:
# PyQt5, PyQt6 >= 6.0.1
img_ptr = int(sip.voidptr(self.shm))
else: else:
# PySide2, PySide6 # PySide2, PySide6
img_ptr = self.shm img_ptr = self.shm