From e760e18882a314e3b4b3fd61fe3e6e631955ff11 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 27 Jul 2017 10:45:36 -0600 Subject: Reselect activeIndex --- framework/qml/TreeView.qml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'framework/qml/TreeView.qml') diff --git a/framework/qml/TreeView.qml b/framework/qml/TreeView.qml index 5bfa7600..e1818a0b 100644 --- a/framework/qml/TreeView.qml +++ b/framework/qml/TreeView.qml @@ -87,18 +87,18 @@ FocusScope { //TODO scroll view so the current index is always visible } - function selectFirst() - { - treeView.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect) - } onActiveFocusChanged: { //Set an initially focused item when the list view receives focus - if (activeFocus && !selection.hasSelection) { - selectFirst() - } - if (!activeFocus) { - selection.clear() + if (activeFocus) { + //If there is a selected index, reset to selected index. + if (root.activeIndex) { + treeView.selection.setCurrentIndex(root.activeIndex, ItemSelectionModel.Current) + } else { + treeView.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect) + } + } else { + selection.clearCurrentIndex() } } -- cgit v1.2.3