Details
Description
Hi,
I'm trying to create a QTexture1D from a Numpy array. From some C++ code I saw I need to create a class that inherits from `QAbstractTextureImage` and implements a `dataGenerator` that returns an object from a class that inherits from QTextureImageDataGenerator. I tried to do that but It was not possible. Bellow a sample in Python:
import numpy as np from PySide6.Qt3DRender import Qt3DRender from PySide6.QtCore import QByteArray class Numpy1DTextureImageDataGenerator(Qt3DRender.QTextureImageDataGenerator): def __init__(self) -> None: super().__init__() self.array = np.random.randn(255).astype(np.float32) self.image = Qt3DRender.QTextureImageData() self.image.setWidth(self.shape[0]) self.image.setHeight(1) self.image.setDepth(1) self.image.setFaces(1) self.image.setFaces(1) self.image.setMipLevels(1) self._data = QByteArray(self.array.tobytes()) self.image.setData(self._data, 0) def __call__(self): return Qt3DRender.QTextureImageDataPtr(self.image) class Numpy1DTextureImageData(Qt3DRender.QAbstractTextureImage): def __init__(self, parent=None) -> None: super().__init__(parent) def dataGenerator(self) -> Qt3DRender.QTextureImageDataGenerator: self._generator = Numpy1DTextureImageDataGenerator() return self._generator texture_image = Numpy1DTextureImageData() texture_generator = Numpy1DTextureImageDataGenerator()
If I try to instantiate `Numpy1DTextureImageData` I get this error:
Traceback (most recent call last): File "/var/home/thiago/Sources/BioScaffolds/test_qt.py", line 37, in <module> texture_image = Numpy1DTextureImageData() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/home/thiago/Sources/BioScaffolds/test_qt.py", line 29, in __init__ super().__init__(parent) TypeError: PySide6.Qt3DCore.Qt3DCore.QNode isn't a direct base class of Numpy1DTextureImageData
And if I try to instantiate `Numpy1DTextureImageDataGenerator` I get this error:
Traceback (most recent call last): File "/var/home/thiago/Sources/BioScaffolds/test_qt.py", line 38, in <module> texture_generator = Numpy1DTextureImageDataGenerator() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/home/thiago/Sources/BioScaffolds/test_qt.py", line 9, in __init__ super().__init__() TypeError: PySide6.Qt3DCore.Qt3DCore.QAbstractFunctor isn't a direct base class of Numpy1DTextureImageDataGenerator
It seems that there is an error in the Qt6 python wrapper.
Attachments
For Gerrit Dashboard: PYSIDE-2610 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
541508,4 | Add QTextureImageData methods returning an enumeration of QOpenGLTexture | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
541700,3 | PySide6: Enable inheritance from QAbstractTextureImage/QTextureImageDataGenerator | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
542249,2 | PySide6: Enable inheritance from QAbstractTextureImage/QTextureImageDataGenerator | 6.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |