如何将滚动条位置设置为最大?它不是文档中所述的 1.0

how to set the scrollbar position to max? its not 1.0 as stated in the docs

更新

通过使用最大 content.x 位置和 0.0-1.0 系数计算所需位置来修复

Component.onCompleted:
{
    var maxContentX = content.width - frame.width
    var factor = 1.0 // 0, 0.5, 1.0
    var newPosition = (maxContentX*factor)/content.width
    hbar.position = newPosition
}

Qt 文档:ScrollBar QML Type

Position Property

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

但仓位永远不会达到 1.0 - 因为仓位仅持有 1 减去柱大小

知道如何计算位置的正确 mid/max 值吗? 我想构建一个在 0%、50% 和 100% 位置之间切换的计时器

Qt 示例:Non-attached Scroll Bars

import QtQuick 2.15
import QtQuick.Controls 2.15

Item
{
  height: 300
  width: 300
  
  Column
  {
    Text { text: "vbar.position: "+vbar.position }
    Text { text: "hbar.position: "+hbar.position }
  }

Rectangle {
    id: frame
    clip: true
    width: 160
    height: 160
    border.color: "black"
    anchors.centerIn: parent  

    Text {
        id: content
        text: "ABC"
        font.pixelSize: 160
        x: -hbar.position * width
        y: -vbar.position * height
    }

    ScrollBar {
        id: vbar
        hoverEnabled: true
        active: hovered || pressed
        orientation: Qt.Vertical
        size: frame.height / content.height
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.bottom: parent.bottom
    }

    ScrollBar {
        id: hbar
        hoverEnabled: true
        active: hovered || pressed
        orientation: Qt.Horizontal
        size: frame.width / content.width
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
    }
}

}

我想我无法回答您问题中的“为什么”部分。但是要获得条的大小,我相信你可以使用滚动条的 contentItem 属性。要获得 0%、50% 和 100%,您可能会这样做(对于水平滚动条):

// 0%
position: 0
// 50%
position: (width - contentItem.width) / width / 2
// 100%
position: (width - contentItem.width) / width