diff options
author | Venugopal Shivashankar <Venugopal.Shivashankar@qt.io> | 2019-12-12 09:41:38 +0100 |
---|---|---|
committer | Venugopal Shivashankar <Venugopal.Shivashankar@qt.io> | 2019-12-12 17:16:22 +0000 |
commit | 486af85cee90e81424f6e5293a399fc308eee7b3 (patch) | |
tree | 4266a959ac8e7aeaea7d732e0598185c0a5b6f95 | |
parent | fb628016895e59cd5adf617281b2b75b26bf3378 (diff) |
Doc: Document the Property function in QtCore
The content for this lived on the wiki till now.
Change-Id: I3e6a2cb7f97ab7021621b7c687299a3199134bb5
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/pyside2/doc/extras/QtCore.Property.rst | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/sources/pyside2/doc/extras/QtCore.Property.rst b/sources/pyside2/doc/extras/QtCore.Property.rst new file mode 100644 index 000000000..209704c46 --- /dev/null +++ b/sources/pyside2/doc/extras/QtCore.Property.rst @@ -0,0 +1,62 @@ +.. currentmodule:: PySide2.QtCore +.. _Property: +Property +******** + +Detailed Description +-------------------- + +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: + +.. code-block:: + :linenos: + +from PySide2.QtCore import QObject, Property + +class MyObject(QObject): + def __init__(self,startval=42): + QObject.__init__(self) + 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) + +Properties in QML expressions +----------------------------- + +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: + +.. code-block:: + :linenos: + +from PySide2.QtCore import QObject, Signal, Property + +class Person(QObject): + def __init__(self, name): + QObject.__init__(self) + self._person_name = name + + def _name(self): + return self._person_name + + @Signal + def name_changed(self): + pass + + name = Property(str, _name, notify=name_changed) |