From e2f7012c5bf966fe72e28a4c676c6d175bb2e1e0 Mon Sep 17 00:00:00 2001 From: ItsLemmy Date: Fri, 26 Sep 2025 23:35:05 -0400 Subject: [PATCH] NScrollView: properly disable horizontal scrrol when setting proper horizontalPolicy --- Widgets/NScrollView.qml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Widgets/NScrollView.qml b/Widgets/NScrollView.qml index 1edca1c1..63e28819 100644 --- a/Widgets/NScrollView.qml +++ b/Widgets/NScrollView.qml @@ -14,10 +14,44 @@ T.ScrollView { property real handleRadius: Style.radiusM * scaling property int verticalPolicy: ScrollBar.AsNeeded property int horizontalPolicy: ScrollBar.AsNeeded + property bool preventHorizontalScroll: horizontalPolicy === ScrollBar.AlwaysOff + property int boundsBehavior: Flickable.StopAtBounds + property int flickableDirection: Flickable.VerticalFlick implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, contentHeight + topPadding + bottomPadding) + // Configure the internal flickable when it becomes available + Component.onCompleted: { + configureFlickable() + } + + // Function to configure the underlying Flickable + function configureFlickable() { + // Find the internal Flickable (it's usually the first child) + for (var i = 0; i < children.length; i++) { + var child = children[i] + if (child.toString().indexOf("Flickable") !== -1) { + // Configure the flickable to prevent horizontal scrolling + child.boundsBehavior = root.boundsBehavior + + if (root.preventHorizontalScroll) { + child.flickableDirection = Flickable.VerticalFlick + child.contentWidth = Qt.binding(() => child.width) + } else { + child.flickableDirection = root.flickableDirection + } + break + } + } + } + + // Watch for changes in horizontalPolicy + onHorizontalPolicyChanged: { + preventHorizontalScroll = (horizontalPolicy === ScrollBar.AlwaysOff) + configureFlickable() + } + ScrollBar.vertical: ScrollBar { parent: root x: root.mirrored ? 0 : root.width - width