[PyQt] objectName properties set in QML not accessible in python
phil at riverbankcomputing.com
Fri Nov 10 13:32:44 GMT 2017
On 9 Nov 2017, at 3:31 pm, Russell Warren <russ at perspexis.com> wrote:
> When you set the `objectName` property of a QObject that has been registered for QML use with `qmlRegisterType`, the resulting `objectName` is not accessible in python.
> See this small self-contained example of the issue:
> Although this can be worked around by defining a replacement `objectName` property in python (see below), it seems like this should not be required. Equivalent C++ code, for example, has no issue accessing the objectName that was set in QML.
> The workaround is to use alternative/back-door means to set/get the `QObject.objectName` property with something like this replacement property definition in the registered class:
> def objectName(self):
> return QtCore.QObject.objectName(self)
> def objectName(self, objectName):
> QtCore.QObject.setObjectName(self, objectName)
> Is there a fundamental reason that objectName can't be accessed in PyQt? It would be nice to not have to use that workaround.
Under the covers there is some proxying going on. Qt does not provide any means to intercept or detect the necessary calls.
More information about the PyQt