1
0

qt history: fix slowness

arghhhhh finalllllllllllly figured it out...
This commit is contained in:
SomberNight
2018-12-10 16:40:32 +01:00
parent e35ed17200
commit b0631f90f8
2 changed files with 9 additions and 3 deletions

View File

@@ -96,9 +96,8 @@ class HistoryModel(QAbstractItemModel, PrintError):
return self.createIndex(row, column) return self.createIndex(row, column)
def data(self, index: QModelIndex, role: Qt.ItemDataRole): def data(self, index: QModelIndex, role: Qt.ItemDataRole):
# requires PyQt5 5.11 # note: this method is performance-critical.
# indexIsValid = QAbstractItemModel.CheckIndexOptions(QAbstractItemModel.CheckIndexOption.IndexIsValid.value) # it is called a lot, and so must run extremely fast.
# assert self.checkIndex(index, indexIsValid)
assert index.isValid() assert index.isValid()
col = index.column() col = index.column()
tx_item = self.transactions.value_from_pos(index.row()) tx_item = self.transactions.value_from_pos(index.row())

View File

@@ -444,6 +444,13 @@ class MyTreeView(QTreeView):
self.setRootIsDecorated(False) # remove left margin self.setRootIsDecorated(False) # remove left margin
self.toolbar_shown = False self.toolbar_shown = False
# When figuring out the size of columns, Qt by default looks at
# the first 1000 rows (at least if resize mode is QHeaderView.ResizeToContents).
# This would be REALLY SLOW, and it's not perfect anyway.
# So to speed the UI up considerably, set it to
# only look at as many rows as currently visible.
self.header().setResizeContentsPrecision(0)
def set_editability(self, items): def set_editability(self, items):
for idx, i in enumerate(items): for idx, i in enumerate(items):
i.setEditable(idx in self.editable_columns) i.setEditable(idx in self.editable_columns)