/
utility.py
31 lines (24 loc) · 929 Bytes
/
utility.py
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
from PyQt5.QtGui import QStandardItemModel
from PyQt5.QtCore import QRegExp, QSortFilterProxyModel,Qt
from PyQt5.QtWidgets import QAbstractItemView
def createModel(parent,rows,cols,colNames):
model=QStandardItemModel(rows, cols+1, parent)
i=0
for c in colNames:
model.setHeaderData(i, Qt.Horizontal, c)
i+=1
proxyModel=QSortFilterProxyModel()
proxyModel.setDynamicSortFilter(True)
proxyModel.setSourceModel(model)
proxyModel.setFilterKeyColumn(0)
return proxyModel
def initView(view):
view.setAlternatingRowColors(True)
view.setSortingEnabled(True)
view.sortByColumn(0, Qt.AscendingOrder)
#view.setSelectionMode(QAbstractItemView.SingleSelection)
def createModelOnView(parent,view, rows,cols,colNames):
model = createModel(parent,rows,cols,colNames)
initView(view)
view.setModel(model)
return model