From fbf2f673f42f1939925733af112b60246ebc496b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 28 Jan 2021 17:47:58 +1000 Subject: [PATCH] fix sidebar model.parent() returning invalid values Triggered a crash when using a model proxy. --- qt/aqt/sidebar.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index b6064c94a..a812bc53b 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -123,9 +123,8 @@ class SidebarModel(QAbstractItemModel): if parentItem is None or parentItem == self.root: return QModelIndex() - row = parentItem.rowForChild(childItem) - if row is None: - return QModelIndex() + grandparent = parentItem.parentItem or self.root + row = grandparent.rowForChild(parentItem) return self.createIndex(row, 0, parentItem) @@ -269,6 +268,10 @@ class SidebarTreeView(QTreeView): model = SidebarModel(root) self.flattened_model = model.flattened() self.setModel(model) + + #from PyQt5.QtTest import QAbstractItemModelTester + #tester = QAbstractItemModelTester(model) + model.expandWhereNeccessary(self) self.mw.taskman.run_in_background(self._root_tree, on_done)