ScrollIndicator QML Type

Vertical or horizontal non-interactive scroll indicator. 更多...

import 语句: import QtQuick.Controls 2.2
Since: Qt 5.7
继承: Control

特性

附加特性

详细描述

ScrollIndicator is a non-interactive indicator that indicates the current scroll position. A scroll indicator can be either vertical or horizontal , and can be attached to any Flickable ,譬如 ListView and GridView .

Flickable {
    // ...
    ScrollIndicator.vertical: ScrollIndicator { }
}
					

Attaching ScrollIndicator to a Flickable

注意: When ScrollIndicator is attached vertically or horizontally to a Flickable, its geometry and the following properties are automatically set and updated as appropriate:

An attached ScrollIndicator re-parents itself to the target Flickable. A vertically attached ScrollIndicator resizes itself to the height of the Flickable, and positions itself to either side of it based on the layout direction . A horizontally attached ScrollIndicator resizes itself to the width of the Flickable, and positions itself to the bottom. The automatic geometry management can be disabled by specifying another parent for the attached ScrollIndicator. This can be useful, for example, if the ScrollIndicator should be placed outside a clipping Flickable. This is demonstrated by the following example:

Flickable {
    id: flickable
    clip: true
    // ...
    ScrollIndicator.vertical: ScrollIndicator {
        parent: flickable.parent
        anchors.top: flickable.top
        anchors.left: flickable.right
        anchors.bottom: flickable.bottom
    }
}
					

Binding the Active State of Horizontal and Vertical Scroll Indicators

Horizontal and vertical scroll indicators do not share the active state with each other by default. In order to keep both indicators visible whilst scrolling to either direction, establish a two-way binding between the active states as presented by the following example:

Flickable {
    anchors.fill: parent
    contentWidth: parent.width * 2
    contentHeight: parent.height * 2
    ScrollIndicator.horizontal: ScrollIndicator { id: hbar; active: vbar.active }
    ScrollIndicator.vertical: ScrollIndicator { id: vbar; active: hbar.active }
}
					

Non-attached Scroll Indicators

It is possible to create an instance of ScrollIndicator without using the attached property API. This is useful when the behavior of the attached scoll indicator is not sufficient or a Flickable is not in use. In the following example, horizontal and vertical scroll indicators are used to indicate how far the user has scrolled over the text (using MouseArea 而不是 Flickable ):

Rectangle {
    id: frame
    clip: true
    width: 160
    height: 160
    border.color: "black"
    anchors.centerIn: parent
    Text {
        id: content
        text: "ABC"
        font.pixelSize: 169
        MouseArea {
            id: mouseArea
            drag.target: content
            drag.minimumX: frame.width - width
            drag.minimumY: frame.height - height
            drag.maximumX: 0
            drag.maximumY: 0
            anchors.fill: content
        }
    }
    ScrollIndicator {
        id: verticalIndicator
        active: mouseArea.pressed
        orientation: Qt.Vertical
        size: frame.height / content.height
        position: -content.y / content.height
        anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
    }
    ScrollIndicator {
        id: horizontalIndicator
        active: mouseArea.pressed
        orientation: Qt.Horizontal
        size: frame.width / content.width
        position: -content.x / content.width
        anchors { left: parent.left; right: parent.right; bottom: parent.bottom }
    }
}
					

另请参阅 ScrollBar , Customizing ScrollIndicator ,和 指示器控件 .

特性文档编制

active : bool

This property holds whether the indicator is active, that is, when the attached Flickable is moving .

It is possible to keep both horizontal and vertical indicators visible while scrolling in either direction.

This property is automatically set when the scroll indicator is attached to a flickable .

[read-only, since QtQuick.Controls 2.3 (Qt 5.10)] horizontal : bool

This property holds whether the scroll indicator is horizontal.

该特性在 QtQuick.Controls 2.3 (Qt 5.10) 引入。

另请参阅 orientation .

[since QtQuick.Controls 2.4 (Qt 5.11)] minimumSize : real

This property holds the minimum size of the indicator, scaled to 0.0 - 1.0 .

This property was introduced in QtQuick.Controls 2.4 (Qt 5.11).

另请参阅 size , visualSize ,和 visualPosition .

orientation : enumeration

This property holds the orientation of the indicator.

可能的值:

常量 描述
Qt.Horizontal Horizontal
Qt.Vertical Vertical (default)

This property is automatically set when the scroll indicator is attached to a flickable .

另请参阅 horizontal and vertical .

position : real

This property holds the position of the indicator, scaled to 0.0 - 1.0 .

This property is automatically set when the scroll indicator is attached to a flickable .

另请参阅 Flickable::visibleArea and visualPosition .

size : real

This property holds the size of the indicator, scaled to 0.0 - 1.0 .

This property is automatically set when the scroll indicator is attached to a flickable .

另请参阅 Flickable::visibleArea , minimumSize ,和 visualSize .

[read-only, since QtQuick.Controls 2.3 (Qt 5.10)] vertical : bool

This property holds whether the scroll indicator is vertical.

该特性在 QtQuick.Controls 2.3 (Qt 5.10) 引入。

另请参阅 orientation .

[since QtQuick.Controls 2.4 (Qt 5.11)] visualPosition : real

This property holds the effective visual position of the indicator, which may be limited by the 最小大小 .

This property was introduced in QtQuick.Controls 2.4 (Qt 5.11).

另请参阅 position and minimumSize .

[since QtQuick.Controls 2.4 (Qt 5.11)] visualSize : real

This property holds the effective visual size of the indicator, which may be limited by the 最小大小 .

This property was introduced in QtQuick.Controls 2.4 (Qt 5.11).

另请参阅 size and minimumSize .


附加特性文档编制

ScrollIndicator.horizontal : ScrollIndicator

This property attaches a horizontal scroll indicator to a Flickable .

Flickable {
    contentWidth: 2000
    ScrollIndicator.horizontal: ScrollIndicator { }
}
					

另请参阅 Attaching ScrollIndicator to a Flickable .

ScrollIndicator.vertical : ScrollIndicator

This property attaches a vertical scroll indicator to a Flickable .

Flickable {
    contentHeight: 2000
    ScrollIndicator.vertical: ScrollIndicator { }
}
					

另请参阅 Attaching ScrollIndicator to a Flickable .