[英]QSortFilterProxyModel - get the number of filtered items
If you do so如果你这样做
def filterAcceptsRow(self, source_row, source_parent):
# Assign a role for filtering
if self.findCheckType == True:
self.setFilterRole(Devices.DevicetypeRole)
elif self.findCheckDepart == True:
self.setFilterRole(Devices.DepartmentRole)
self.countFindItems = self.rowCount()
return super(SelectModel, self).filterAcceptsRow(source_row, source_parent)
The compiler throws an error编译器抛出错误
Connected to pydev debugger (build 193.5662.61)
Traceback (most recent call last):
File "F:\.....\app.py", line 1230, in filterAcceptsRow
self.countFindItems = self.rowCount()
RecursionError: maximum recursion depth exceeded while calling a Python object
How can I get the number of filtered items?如何获得过滤项目的数量?
When you modify filter inside filterAcceptsRow
it invalidates filter which causes filterAcceptsRow
evaluated for all rows, which is infinite loop.当您修改filterAcceptsRow
内的过滤器时,它会使过滤器无效,从而导致对所有行评估filterAcceptsRow
,这是无限循环。
Number of filtered rows can be calculated like this: self.sourceModel().rowCount() - self.rowCount()
.过滤的行数可以这样计算: self.sourceModel().rowCount() - self.rowCount()
。
Also instead of if something == True:
you can write if something:
.也可以代替if something == True:
你可以写if something:
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.