From 509c4a08714c480bec6c21f38ccdd7a738221216 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 2 Sep 2020 14:40:06 -0400 Subject: [PATCH] Add defaultCurrentIndex to H(List/Grid)View When the model of a view changes, Qt automatically sets the currentIndex to 0. Reset it back to the set default (usually -1) instead. --- src/gui/Base/HGridView.qml | 5 ++++- src/gui/Base/HListView.qml | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/Base/HGridView.qml b/src/gui/Base/HGridView.qml index 56350e85..6ca91c04 100644 --- a/src/gui/Base/HGridView.qml +++ b/src/gui/Base/HGridView.qml @@ -6,6 +6,8 @@ import QtQuick.Controls 2.12 GridView { id: gridView + property int defaultCurrentIndex: -1 + property alias cursorShape: mouseArea.cursorShape property int currentItemHeight: currentItem ? currentItem.height : 0 @@ -65,7 +67,7 @@ GridView { } - currentIndex: -1 + currentIndex: defaultCurrentIndex keyNavigationWraps: true highlightMoveDuration: theme.animationDuration @@ -118,6 +120,7 @@ GridView { } onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0 + onModelChanged: currentIndex = defaultCurrentIndex HKineticScrollingDisabler { id: mouseArea diff --git a/src/gui/Base/HListView.qml b/src/gui/Base/HListView.qml index 77037da7..2cec4317 100644 --- a/src/gui/Base/HListView.qml +++ b/src/gui/Base/HListView.qml @@ -6,6 +6,8 @@ import QtQuick.Controls 2.12 ListView { id: listView + property int defaultCurrentIndex: -1 + property int currentItemHeight: currentItem ? currentItem.height : 0 property var checked: ({}) @@ -76,7 +78,7 @@ ListView { } - currentIndex: -1 + currentIndex: defaultCurrentIndex keyNavigationWraps: true highlightMoveDuration: theme.animationDuration highlightResizeDuration: theme.animationDuration @@ -135,6 +137,7 @@ ListView { } onSelectedCountChanged: if (! selectedCount) lastCheckedDelegateIndex = 0 + onModelChanged: currentIndex = defaultCurrentIndex HKineticScrollingDisabler { width: enabled ? parent.width : 0