The Property function lets you declare properties that behave both as Qt and Python properties, and have their setters and getters defined as Python functions.
Here is an example that illustrates how to use this function:
1 |
|
from PySide2.QtCore import QObject, Property
QObject.__init__(self) self.ppval = startval
return self.ppval
self.ppval = val
pp = Property(int, readPP, setPP)
obj = MyObject() obj.pp = 47 print(obj.pp)
If you are using properties of your objects in QML expressions, QML requires that the property changes are notified. Here is an example illustrating how to do this:
1 |
|
from PySide2.QtCore import QObject, Signal, Property
QObject.__init__(self) self._person_name = name
return self._person_name
@Signal def name_changed(self):
pass
name = Property(str, _name, notify=name_changed)