diff --git a/src/quickcontrols/doc/snippets/qtquickcontrols-scrollbar-policy-alwayson-when-needed.qml b/src/quickcontrols/doc/snippets/qtquickcontrols-scrollbar-policy-alwayson-when-needed.qml new file mode 100644 index 0000000000..0b40b79b56 --- /dev/null +++ b/src/quickcontrols/doc/snippets/qtquickcontrols-scrollbar-policy-alwayson-when-needed.qml @@ -0,0 +1,21 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +import QtQuick +import QtQuick.Controls + +ListView { + id: listView + anchors.fill: parent + model: 20 + delegate: ItemDelegate { + width: listView.width + text: modelData + } + + ScrollBar.vertical: ScrollBar { + //! [1] + policy: listView.contentHeight > listView.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff + //! [1] + } +} diff --git a/src/quickcontrols/doc/snippets/qtquickcontrols-scrollbar-policy.qml b/src/quickcontrols/doc/snippets/qtquickcontrols-scrollbar-policy-alwayson.qml similarity index 100% rename from src/quickcontrols/doc/snippets/qtquickcontrols-scrollbar-policy.qml rename to src/quickcontrols/doc/snippets/qtquickcontrols-scrollbar-policy-alwayson.qml diff --git a/src/quicktemplates/qquickscrollbar.cpp b/src/quicktemplates/qquickscrollbar.cpp index 171d842a32..e99887f940 100644 --- a/src/quicktemplates/qquickscrollbar.cpp +++ b/src/quicktemplates/qquickscrollbar.cpp @@ -656,7 +656,17 @@ void QQuickScrollBar::resetInteractive() The following example keeps the vertical scroll bar always visible: - \snippet qtquickcontrols-scrollbar-policy.qml 1 + \snippet qtquickcontrols-scrollbar-policy-alwayson.qml 1 + + Styles may use this property in combination with the \l active property + in order to implement transient scroll bars. Transient scroll bars are + hidden shortly after the last interaction event (hover or press). This + is typically done by animating the opacity of the scroll bar. To override + this behavior, set the policy to \c ScrollBar.AlwaysOn or + \c ScrollBar.AlwaysOff, depending on the size of the content compared to + its view. For example, for a vertical \l ListView: + + \snippet qtquickcontrols-scrollbar-policy-alwayson-when-needed.qml 1 */ QQuickScrollBar::Policy QQuickScrollBar::policy() const {