Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2610

It's not possible to inherit from QTextureImageDataGenerator and QAbstractTextureImage

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4: Low
    • 6.7.0, 6.6.3
    • 6.6.2
    • PySide
    • None
    • All
    • de503531f (dev), c892b9299 (dev), b9d5d3fc8 (6.6)

    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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            manuelo Thiago Moraes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews