PyQt6 6.0.1 changes QImage constructor api

This commit is contained in:
KIU Shueng Chuan 2021-02-07 07:14:24 +08:00
parent feaa8fe5fb
commit 54d7c591b5
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
# 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
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)

View File

@ -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':
# 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