[PyQt] [BUG] Can't override protected method QSGMaterialShader::compile() in Python

Vladimir Rutsky rutsky.vladimir at gmail.com
Thu Jun 18 20:18:20 BST 2015


On Tue, Jun 2, 2015 at 4:48 PM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On 02/06/2015 1:14 pm, Vladimir Rutsky wrote:
>>
>> On Tue, Jun 2, 2015 at 2:01 PM, Phil Thompson
>> <phil at riverbankcomputing.com> wrote:
>>>
>>> On 02/06/2015 11:50 am, Vladimir Rutsky wrote:
>>>>
>>>>
>>>> Overriden QSGMaterialShader::compile() is never called in Python.
>>>
>>>
>>>
>>> How is the shader being created?
>>>
>>> Phil
>>
>>
>> The shader is created when Qt calls createShader() in my derivative of
>> QSGMaterial:
>>
>> class MyMaterialShader(QSGMaterialShader):
>>     ...
>>
>>     def initialize(self):
>>         # This method and some others are successfully called
>>         ...
>>
>>     def compile(self):
>>         # This code never called
>>         print("Test")
>>         return super().compile()
>>
>>
>> class MyMaterial(QSGMaterial):
>>     _type = QSGMaterialType()
>>
>>     def __init__(self):
>>         super().__init__()
>>
>>     def compare(self, other_material):
>>         if self is other_material:
>>             return 0
>>         else:
>>             return -1 if id(self) < id(other_material) else 1
>>
>>     def createShader(self):
>>         # TODO: PyQt bug with ownage
>>         self._shader = MyMaterialShader()
>>         return self._shader
>>
>>     def type(self):
>>         return self._type
>>
>> MyMaterial is used as material for QSGGeometryNode().
>
>
> Can you send me a short, complete script that demonstrates the problem?
>
> Thanks,
> Phil


I was wrong about this issue: overriden QSGMaterialShader::compile()
is properly called from Python.
I missed, that it is required by Qt to set
QSGMaterial.CustomCompileStep flag for used material, so Qt will call
QSGMaterialShader::compile().

Regards,

Vladimir Rutsky


More information about the PyQt mailing list