Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
Qt for Python UsingQtProperties: Difference between revisions
Jump to navigation
Jump to search
AutoSpider (talk | contribs) (Decode HTML entity numbers) |
Henri Vikki (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
[[Category:LanguageBindings::PySide]] | [[Category:LanguageBindings::PySide]] | ||
Line 6: | Line 6: | ||
'''English''' [[:Using_Qt_Properties_in_PySide_Korean|한국어]] | '''English''' [[:Using_Qt_Properties_in_PySide_Korean|한국어]] | ||
PySide provides a <code>Property</code> 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. | PySide provides a <code>Property</code> 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. |
Revision as of 08:35, 26 March 2015
English 한국어
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:
from PySide.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)
The complete specification for PySide's property system is given in PSEP 103.
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:
class Person(QtCore.QObject):
def ''init''(self, name):
QtCore.QObject.''init''(self)
self._person_name = name
def _name(self):
return self._person_name
@QtCore.Signal
def name_changed(self): pass
name = QtCore.Property(unicode, _name, notify=name_changed)