QTableView only requests model-specific data for items in its viewport, so the size of your data doesnβt really affect the speed. Since you already subclassed QAbstractListModel , you can override it to return only a small set of rows when it is initialized and change it canFetchMore return True if the total volume of records is not displayed. Although with the size of your data, you might want to create a database and use QSqlQueryModel or QSqlTableModel , both of them do lazy loading in 256 groups.
To get a smoother loading of elements, you can connect to the valueChanged signal of your QTableView.verticalScrollBar() and depending on the difference between it, value and maximum has something like:
while xCondition: if self.model.canFetchMore(): self.model.fetchMore()
Using setIndexWidget slows down your application significantly. You can use QItemDelegate and set its paint to display a button with something like:
class MyItemDelegate(QtGui.QItemDelegate): def __init__(self, parent=None): super(MyItemDelegate, self).__init__(parent) def paint(self, painter, option, index): text = index.model().data(index, QtCore.Qt.DisplayRole).toString() pushButton = QtGui.QPushButton() pushButton.setText(text) pushButton.setGeometry(option.rect) painter.save() painter.translate(option.rect.x(), option.rect.y()) pushButton.render(painter) painter.restore()
And configure it with
myView.setItemDelegateForColumn(columnNumber, myItemDelegate)
user1006989
source share