2 from PyQt4.QtCore import *
3 from PyQt4.QtGui import *
5 ####################################################################
7 app = QApplication(sys.argv)
12 ####################################################################
13 class MyWindow(QWidget):
14 def __init__(self, *args):
15 QWidget.__init__(self, *args)
18 list_data = ["Tarek","Ehab","Galal"]
19 lm = MyListModel(list_data, self)
21 lv.setViewMode(QListView.IconMode)
25 layout = QVBoxLayout()
27 self.setLayout(layout)
29 ####################################################################
30 class MyListModel(QAbstractListModel):
31 def __init__(self, datain, parent=None, *args):
32 """ datain: a list where each item is a row
34 QAbstractListModel.__init__(self, parent, *args)
35 self.listdata = datain
37 def rowCount(self, parent=QModelIndex()):
38 return len(self.listdata)
40 def data(self, index, role):
41 if index.isValid() and role == Qt.DisplayRole:
42 return QVariant(self.listdata[index.row()])
46 ####################################################################
47 if __name__ == "__main__":