Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.12.0
-
None
Description
With PyQt5, I use Q_CLASSINFO to define a "DefaultProperty" in a Python class exposed to QML.
The import does not exist in PySide2
As per Cristian's suggestion, I tried the following, which fails:
from PySide2.QtCore import QUrl, QObject, ClassInfo, Property, Signal from PySide2.QtQuick import QQuickView from PySide2.QtQml import qmlRegisterType from PySide2.QtGui import QGuiApplication ClassInfo(DefaultProperty='poil') class MyClass(QObject): def __init__(self, parent = None): super(MyClass, self).__init__(parent) self._poil = None def get_poil(self): return self._poil def set_poil(self, p): self._poil = p poilChanged = Signal() poil = Property(QObject, get_poil, set_poil, notify = poilChanged) qmlRegisterType(MyClass, "MyModule", 1, 0, "MyClass") if __name__ == '__main__': app = QGuiApplication(sys.argv) view = QQuickView() view.setSource( QUrl.fromLocalFile('whatever.qml') ) view.show() QGuiApplication.processEvents() #whatever.qml:11:9: Cannot assign to non-existent default property MyClass{}
whatever.qml:
import QtQuick 2.5 import MyModule 1.0 Rectangle { height: 800 width: 800 color: "blue" MyClass { MyClass{} //line 11 (!) Component.onCompleted: console.log(poil) } }