[PyQt] objectName properties set in QML not accessible in python

Russell Warren russ at perspexis.com
Thu Nov 9 15:31:58 GMT 2017


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:

https://gist.github.com/rwarren/995e7ddc373f7119c51737fcd4aba0cc

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:

    @pyqtProperty(str)
    def objectName(self):
        return QtCore.QObject.objectName(self)

    @objectName.setter
    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.

Russ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20171109/23d328f6/attachment.html>


More information about the PyQt mailing list