[PySide] QtCore.Property or python decorators

309 views
Skip to first unread message

Sergey Krasilnikov

unread,
Apr 18, 2011, 6:08:12 AM4/18/11
to pys...@lists.pyside.org
Hi all!
I tried two ways to determine the properties in PySide: QtCore.Property and @property decorator
sample code based on http://www.pyside.org/docs/pseps/psep-0103.html
both methods work with Qt State Machine Framework
which method is best to use?
p.s. 
why print objA.pp returns <Property object at 0x7fa0320ba0d8> ?
pyside 1.0.1, Qt4.7, ubuntu 10.10 x64

-------------------------------------------------------------------------------------

from PySide import QtCore

class MyObject(QtCore.QObject):
    def __init__(self,startval=42):
        self.ppval = startval
 
    def readPP(self):
        return self.ppval
 
    def setPP(self,val):
        self.ppval = val
 
    pp = QtCore.Property(int, readPP, setPP)
 
objA = MyObject()
print objA.pp
objA.pp = 47
print objA.pp


class MyObject1(object):
    def __init__(self, startval=42):
        self.ppval = startval

    @property
    def pp(self):
        return self.ppval

    @pp.setter
    def pp(self, val):
        self.ppval = val


objB = MyObject1(10)
print objB.pp
objB.pp = 47
print objB.pp
Reply all
Reply to author
Forward
0 new messages