Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PySide.QtCore import *
- from PySide.QtGui import *
- from PySide.QtDeclarative import *
- class TestAList(QAbstractListModel):
- def __init__(self,parent = None):
- QAbstractListModel.__init__(self,parent)
- # Set some roles
- self.roles = dict()
- self.roles[Qt.UserRole+1] = 'key1'
- self.roles[Qt.UserRole+2] = 'key2'
- self.roles[Qt.DisplayRole] = 'display'
- self.setRoleNames(self.roles)
- def rowCount(self, parent=QModelIndex()):
- return 3
- #def columnCount(self, parent=QModelIndex()):
- # return 1
- def data(self, index, role):
- if index.isValid() and role == Qt.UserRole+1:
- return "hello(from abstractlist!)"
- elif index.isValid() and role == Qt.UserRole+2:
- return TestAList()
- elif index.isValid() and role == Qt.DisplayRole:
- return "display"
- return None
- class TestItem(QObject):
- dataChanged = Signal()
- def getAbstractList(self):
- if not hasattr(self,'_alist'):
- self._alist = TestAList()
- return self._alist
- def getNormalList(self):
- if not hasattr(self,'_nlist'):
- d = dict()
- d['key1'] = 'hello from normal list' # Simple string value
- d['child'] = [1,2,3,4] # list value.
- self._nlist = [d, d, d]
- return self._nlist # return a list of these dict objects
- alist = Property(QObject, getAbstractList, notify=dataChanged)
- plist = Property(list, getNormalList, notify=dataChanged)
- def __init__(self, parent = None):
- QObject.__init__(self, parent)
- print "INIT FIN"
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- view = QDeclarativeView()
- tobject = TestItem()
- view.rootContext().setContextProperty("pythonQObject", tobject)
- view.setSource('list-test.qml')
- view.show()
- app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment