self collection_model CollectionModel self collection_model_pro xy QtG

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
self.collection_model = CollectionModel()
self.collection_model_proxy = QtGui.QSortFilterProxyModel()
self.collection_model_proxy.setSourceModel(self.collection_model)
def cmpfilterAcceptsRow(row, parent):
"Custon filter for QSortFilterProxyModel for collection"
col = self.collection_model
if parent.isValid():
pd = col.data(parent, QtCore.Qt.DisplayRole).toString()
if pd.contains(self.collection_model_proxy.filterRegExp()):
return True
def search(item):
data = col.data(item, QtCore.Qt.DisplayRole).toString()
if data.contains(self.collection_model_proxy.filterRegExp()):
return True
nchildren = col.rowCount(item)
for x in range(nchildren):
child = col.index(x, 0, item)
if search(child):
return True
return False
item = col.index(row, 0, parent)
return search(item)
self.collection_model_proxy.filterAcceptsRow = cmpfilterAcceptsRow
self.ui.treeView.setModel(self.collection_model_proxy)