def cmpfilterAcceptsRow row parent Custon filter for QSortFilterProxyM

 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
def cmpfilterAcceptsRow(row, parent):
"Custon filter for QSortFilterProxyModel for collection"
col = self.collection_model
def backsearch(parent):
if parent.isValid():
pd = col.data(parent, QtCore.Qt.DisplayRole).toString()
if pd.contains(self.collection_model_proxy.filterRegExp()):
return True
else:
return backsearch(parent.parent())
else:
return False
if backsearch(parent):
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)