QSortFilterProxyModel - 获取过滤项目的数量

QSortFilterProxyModel - get the number of filtered items

如果你这样做

    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)

编译器抛出错误

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

如何获取筛选项的数量?

当您在 filterAcceptsRow 中修改过滤器时,它会使过滤器无效,这会导致 filterAcceptsRow 对所有行进行评估,这是无限循环。

筛选的行数可以这样计算:self.sourceModel().rowCount() - self.rowCount().

你也可以写 if something:.

而不是 if something == True: