ScrollView QML Type
可滚动视图。更多
Import Statement: | import QtQuick.Controls |
Inherits: |
属性
- contentChildren : list<Item>
- contentData : list<QtObject>
- effectiveScrollBarHeight : real
(since 6.6)
- effectiveScrollBarWidth : real
(since 6.6)
详细说明
ScrollView 为用户定义的内容提供滚动功能。它既可以用来替换Flickable ,也可以用来装饰现有的内容。
第一个示例演示了 ScrollView 的最简单用法。
ScrollView { width: 200 height: 200 Label { text: "ABC" font.pixelSize: 224 } }
第二个示例说明了如何使用现有的Flickable ,即ListView 。
ScrollView { width: 200 height: 200 ListView { model: 20 delegate: ItemDelegate { text: "Item " + index required property int index } } }
注意: 从 Qt-6.0 开始,如果不使用 Flickable 作为子代,ScrollView 会自动剪切其内容。如果不希望这样,您可以将自己的 Flickable 设置为子代,并显式控制 Flickable 上的clip 属性。
大小
与 Flickable 一样,使用 ScrollView 时也有几件事需要注意:
- 如果 ScrollView 中只使用了单个项目,那么内容大小会根据其所包含项目的隐式大小自动计算。但是,如果使用了多个项目(或未提供隐式尺寸),则必须将contentWidth 和contentHeight 属性设置为所含项目的组合尺寸。
- 如果内容大小小于或等于 ScrollView 的大小,则无法滚动。
- 如果希望 ScrollView 只垂直滚动,可以将contentWidth 绑定到availableWidth (反之亦然,将 contentHeight 绑定到 )。这样,在考虑到任何填充或滚动条的情况下,内容将填满 ScrollView 内水平方向的所有可用空间。
滚动条
水平和垂直滚动条可使用ScrollBar.horizontal 和ScrollBar.vertical 附加属性进行访问和自定义。下面的示例调整了滚动条策略,使水平滚动条始终处于关闭状态,而垂直滚动条始终处于打开状态。
ScrollView { // ... ScrollBar.horizontal.policy: ScrollBar.AlwaysOff ScrollBar.vertical.policy: ScrollBar.AlwaysOn }
触摸与鼠标交互
在触摸状态下,ScrollView 会启用滑动功能,并使滚动条非交互式。
在与鼠标设备交互时,弹动功能被禁用,滚动条是交互式的。
通过将interactive 属性显式设置为true
或false
,可以使滚动条在触摸时交互,或在与鼠标设备交互时非交互。
ScrollView { // ... ScrollBar.horizontal.interactive: true ScrollBar.vertical.interactive: true }
另请参阅 ScrollBar,ScrollIndicator,Customizing ScrollView,Container Controls, andFocus Management inQt Quick Controls 。
属性文档
该属性包含内容子项列表。
该列表包含已在 QML 中声明为视图子项的所有项目。
注意: 与contentData
不同,contentChildren
不包括非视觉 QML 对象。
另请参阅 Item::children 和contentData 。
该属性包含内容数据列表。
该列表包含在 QML 中声明为视图子对象的所有对象。
注意: 与contentChildren
不同,contentData
包含非可视 QML 对象。
另请参阅 Item::data 和contentChildren 。
effectiveScrollBarHeight : real |
该属性包含水平滚动条的有效高度。当滚动条策略为QQuickScrollBar::AlwaysOff
或滚动条不可见时,该属性为0
。
该属性在 Qt 6.6 中引入。
另请参阅 ScrollBar::policy 。
effectiveScrollBarWidth : real |
该属性保存垂直滚动条的有效宽度。当滚动条策略为QQuickScrollBar::AlwaysOff
或滚动条不可见时,此属性为0
。
该属性在 Qt 6.6 中引入。
另请参见 ScrollBar::policy 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.