Doc: explain how to always show ScrollBar when needed
Until we e.g. add a transient property to ScrollBar, we should document
how users can ensure that it is always visible when the content size
exceeds the view size.
Task-number: QTBUG-76895
Change-Id: Iaf755f51ca9fd3865ae710a2cba13b58b897930e
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 62e3830944
)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
228efa08af
commit
30015a617e
|
@ -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]
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue