Details
-
Bug
-
Resolution: Fixed
-
Not Evaluated
-
None
-
5.15.0
-
None
Description
Hello. I know what can be used PySide with QML. For access to property in Python sourcse needed register context property for QML in Python source, like this:
... class MyMain(QObject): def __init__(self): super(MyMain, self).__init__() @Property(str) def myprop(self): return 'My Property' ... mymain = MyMain() engine = QQmlApplicationEngine() engine.rootContext().setContextProperty('mymain', mymain)
in QML
... Lable {text: mymain.myprop} ...
But i have question. Maybe create context property classes which is an attribute of the class:
... class SubCl(QObject): def __init__(self): super(SubCl, self).__init__() @Property(str) def subprop(self): return 'Sub Property' class MyMain(QObject): def __init__(self): super(MyMain, self).__init__() self.sub = SubCl() @Property(QObject) def subcl(self): return self.sub @Property(str) def myprop(self): return 'My Property' ... mymain = MyMain() engine = QQmlApplicationEngine() engine.rootContext().setContextProperty('mymain', mymain) # in QML: mymain.subcl.subprop - worked engine.rootContext().setContextProperty('submain', mymain.sub) # or engine.rootContext().setContextProperty('submain', mymain.subcl) # in QML: submain.subprop - not worked, why?
This is bug or feature?