-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListModel.py
More file actions
56 lines (47 loc) · 2.04 KB
/
Copy pathListModel.py
File metadata and controls
56 lines (47 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#coding=utf-8
from PyQt5.QtCore import QAbstractListModel, Qt, QModelIndex, QVariant, QSize
from PyQt5.QtGui import QIcon, QFont
class ListModel(QAbstractListModel):
def __init__(self, DataList):
super().__init__()
self.ListItemData = []
self.data = DataList
self.Data_init()
def data(self, index, role):
if index.isValid() or (0 <= index.row() < len(self.ListItemData)):
if role == Qt.DisplayRole:
return QVariant(self.ListItemData[index.row()]['name']+'\n'+self.ListItemData[index.row()]['signature'])
elif role == Qt.DecorationRole:
return QVariant(QIcon(self.ListItemData[index.row()]['iconPath']))
elif role == Qt.SizeHintRole:
return QVariant(QSize(70,80))
elif role == Qt.TextAlignmentRole:
return QVariant(int(Qt.AlignLeft|Qt.AlignVCenter))
elif role == Qt.FontRole:
font = QFont()
font.setPixelSize(20)
return QVariant(font)
else:
return QVariant()
def rowCount(self, parent = QModelIndex()):
return len(self.ListItemData)
def Data_init(self):
for item in self.data:
self.addItem(item)
# for i in range(1, 8):
# randname = Random_Name.getname()
# ItemData = {'name':'', 'iconPath':'', 'signature':''}
# ItemData['name'] = randname
# ItemData['iconPath'] = "./res/"+ str(i) + ".jpg"
# ItemData['signature'] = '暂无个性签名'
# self.addItem(ItemData)
def addItem(self, itemData):
if itemData:
self.beginInsertRows(QModelIndex(), len(self.ListItemData), len(self.ListItemData) + 1)
self.ListItemData.append(itemData)
self.endInsertRows()
def deleteItem(self, index):
del self.ListItemData[index]
def getItem(self, index):
if index > -1 and index < len(self.ListItemData):
return self.ListItemData[index]