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.
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user