QAbstractTableModel 视图中有哪些行

What rows are in view of a QAbstractTableModel

我有一个带有自定义 QAbstractTableModel 的自定义 QTableView。我更新数据已更改的每一行。管理数据的 class 有一个脏标志,可以很好地帮助减少更新次数。

当我有大量行(1000 行或更多)时,table 的响应速度会稍差一些。我不想对每一行进行 for 循环来检查它是否脏,而是想循环遍历用户可见的 20 行左右,但我似乎无法确定如何获取该信息。

是否有方法或方便的方式来确定哪些行对 QAbstractTableModel 可见?

以下将仅更新用户可见的行:

minRow = treeView.rowAt(0) # very top of scrollable area
if minRow >= 0: # ensure there is at least one row
    maxRow = treeView.rowAt(treeView.height()) # very bottom...

    # there may not be enough rows to fill scrollable area
    if maxRow < 0: maxRow = model.rowCount() - 1

    for row in range(minRow, maxRow + 1):
        model.dataChanged.emit(model.index(row, 0), model.index(row, model.columnCount()))