From b26bfb18616e2a4baf33f9f1a2c147e3f5512de6 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Sat, 29 Feb 2020 19:08:44 +0300 Subject: TreeView: update currentIndex on model changes The previous binding was not getting re-evaluated when the model was being reset or when rows were been inserted or removed. Here we use a counter variable, whose value change will force the evaluation of the binding. Fixes: QTBUG-53097 Change-Id: I76afebbda78ab477cf65631337a8bad51ca5428d Reviewed-by: Mitch Curtis --- src/controls/TreeView.qml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/controls/TreeView.qml b/src/controls/TreeView.qml index 6a38acff5..2bedb9e64 100644 --- a/src/controls/TreeView.qml +++ b/src/controls/TreeView.qml @@ -49,7 +49,7 @@ BasicTableView { property var model: null property alias rootIndex: modelAdaptor.rootIndex - readonly property var currentIndex: modelAdaptor.mapRowToModelIndex(__currentRow) + readonly property var currentIndex: modelAdaptor.updateCount, modelAdaptor.mapRowToModelIndex(__currentRow) property ItemSelectionModel selection: null signal activated(var index) @@ -96,6 +96,12 @@ BasicTableView { id: modelAdaptor model: root.model + // Hack to force re-evaluation of the currentIndex binding + property int updateCount: 0 + onModelReset: updateCount++ + onRowsInserted: updateCount++ + onRowsRemoved: updateCount++ + onExpanded: root.expanded(index) onCollapsed: root.collapsed(index) } -- cgit v1.2.3