English 한국어
Using Qt Properties in PySide
PySide provides a Property function which allows for declaring properties that simultaneously behave both as Qt and Python properties, and have their setters and getters defined as Python functions.
A short example illustrating defining and accessing a Qt property from Python is given below:
- def __init__(self,startval=42):
- self.ppval = startval
- def readPP(self):
- return self.ppval
- def setPP(self,val):
- self.ppval = val
- pp = Property(int, readPP, setPP)
- obj = MyObject()
- obj.pp = 47
- print obj.pp
The complete specification for PySide’s property system is given in PSEP 103 [pyside.org].
Properties in QML expressions
If you are using properties of your objects in QML expressions, QML requires the property to be NOTIFYable. This can be done using a simple signal:
- def __init__(self, name):
- self._person_name = name
- def _name(self):
- return self._person_name
- @QtCore.Signal
- def name_changed(self): pass
Emit the signal when the data changes, and QML will automatically update all expressions depending on the value.

