[PyQt] Inherit from QBufferDataGenerator

Phil Thompson phil at riverbankcomputing.com
Wed May 22 17:25:42 BST 2019


On 17/05/2019 11:12, Maxim Okhotskiy wrote:
> Hi, I have a difficulty with inheriting from QBufferDataGenerator:
> I use python3 and
> 
> PyQt5>=5.12
> pyqt3d>=5.12
> pyopengl
> 
> Here's an example.py
> 
> from PyQt5.QtCore import *from PyQt5.Qt3DCore import *from
> PyQt5.Qt3DRender import *
> class SomeDataGenerator(QBufferDataGenerator):
>     def __init__(self, some_bytes):
>         super().__init__()
>         self._bytes = some_bytes
> 
>     def __call__(self):
>         return self._bytes
> 
>     def __eq__(self, other):
>         return (self._bytes == other._bytes)
> 
>     def __neq__(self, other):
>         return not (self._bytes == other._bytes)
> 
>     def id(self):
>         return functorTypeId(SomeDataGenerator)
> 
> 
> someBytes = QByteArray()
> someBuffer = QBuffer(QBuffer.VertexBuffer)
> someDataGenerator = SomeDataGenerator(someBytes)
> someBuffer.setDataGenerator(someDataGenerator)
> 
> Run provides the following result:
> 
> $ python3 example.py...TypeError:
> PyQt5.Qt3DRender.QBufferDataGenerator cannot be instantiated or
> sub-classed

The problem is how to implement workable bindings for QAbstractFunctor. 
I think it's probably possible to do - but I'm not sure it is worth it.

Is there any need to use setDataGenerator() rather than just setData()?

If setData() is adequate then I would probably remove QAbstractFunctor 
and all related sub-classes and methods.

Phil


More information about the PyQt mailing list