From 3eaaa228d8f1abaa29b9388802486fe82403bd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Dezeiraud?= Date: Sat, 16 Nov 2024 20:27:48 +0100 Subject: [PATCH] Add property autoResetScroll to FluScrollablePage I use it in my app, I think it can be useful to integrate the featurein the main project. This property autoResetScroll if true reset the scroll at the top when the StackView.onActivated is called. So the first time a page is view but also when the user go back in the stack. --- .../imports/FluentUI/Controls/FluScrollablePage.qml | 13 +++++++++++++ .../imports/FluentUI/Controls/FluScrollablePage.qml | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Qt5/imports/FluentUI/Controls/FluScrollablePage.qml b/src/Qt5/imports/FluentUI/Controls/FluScrollablePage.qml index 5e1eb09f..573df65d 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluScrollablePage.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluScrollablePage.qml @@ -5,8 +5,11 @@ import QtQuick.Controls 2.15 import FluentUI 1.0 FluPage { + property bool autoResetScroll: false default property alias content: container.data + Flickable{ + id: flickable clip: true anchors.fill: parent ScrollBar.vertical: FluScrollBar {} @@ -17,4 +20,14 @@ FluPage { width: parent.width } } + + function resetScroll() { + flickable.contentY = 0; + } + + StackView.onActivated: { + if (autoResetScroll) { + resetScroll(); // Call this function to reset the scroll position to the top + } + } } diff --git a/src/Qt6/imports/FluentUI/Controls/FluScrollablePage.qml b/src/Qt6/imports/FluentUI/Controls/FluScrollablePage.qml index ca710e5f..51e7ade6 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluScrollablePage.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluScrollablePage.qml @@ -5,8 +5,11 @@ import QtQuick.Controls import FluentUI FluPage { + property bool autoResetScroll: false default property alias content: container.data + Flickable{ + id: flickable clip: true anchors.fill: parent ScrollBar.vertical: FluScrollBar {} @@ -17,4 +20,14 @@ FluPage { width: parent.width } } + + function resetScroll() { + flickable.contentY = 0; + } + + StackView.onActivated: { + if (autoResetScroll) { + resetScroll(); // Call this function to reset the scroll position to the top + } + } }