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

Vladimir Rutsky rutsky.vladimir at gmail.com
Tue Jun 2 13:51:05 BST 2015


Sorry, Phil, I forgot to sent to mailing list.


---------- Forwarded message ----------
From: Vladimir Rutsky <rutsky.vladimir at gmail.com>
Date: Tue, Jun 2, 2015 at 3:14 PM
Subject: Re: [PyQt] [BUG] Can't override protected method
QSGMaterialShader::compile() in Python
To: Phil Thompson <phil at riverbankcomputing.com>


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().

--
Vladimir Rutsky


More information about the PyQt mailing list