gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 08:48:35 24 4
gpt4 key购买 nike

更新
通过使用最大 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 个负柱尺寸
  • 我不明白在 0 和 1 之间缩放位置的意义是什么,然后让它与条形大小直接相关
  • 上面的位置值(1 减去条形大小)是否有任何有意义的用法?
  • 有没有办法获得酒吧的大小?

  • enter image description here
    知道如何计算位置的正确中/最大值吗?
    我想构建一个在 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属性(property)。要获得 0%、50% 和 100%,您可能可以执行以下操作(对于水平滚动条):

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

    关于qml - 如何将滚动条位置设置为最大?它不是文档中所述的 1.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64185549/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com