我可以控制委托到 QML 中 PathView 的附加点吗?

Can I controll the attachment point of a delegate to a PathView in QML?

我正在尝试在 QtQuick 中围绕 PathViews 进行思考。我可以毫不费力地创建一个 PathView 和一个合适的委托,以便呈现这些委托 "along the path"。但是,我找不到关于此 "along" 含义的任何定义,即代表如何附加到路径。考虑以下示例,其中一条路径穿过页面的垂直中心:

import QtQuick 2.8
import QtQuick.Controls 2.1

ApplicationWindow {

    visible: true
    id: app
    width: 1280
    height: 720
    color: "#330000"

    PathView {
        id: pathView
        anchors.fill: parent
        model: 6

        delegate: Rectangle {
            id: item
            height: app.height * 0.5
            width: app.width * 0.25

            border.width: 5
            border.color: "#2f2f2f"
            color: "#d2d2d2"

            scale: PathView.itemscale
            z: PathView.z
        }

        interactive: true

        pathItemCount: 5
        preferredHighlightEnd: 0.5
        preferredHighlightBegin: 0.5

        path: Path {        
            startX: 0
            startY: app.height * 0.5

            PathAttribute { name: "z"; value: 0 }
            PathAttribute { name: "itemscale"; value: 0.5 }

            PathLine {
                x: app.width * 0.5
                y: app.height * 0.5
            }

            PathAttribute { name: "z"; value: 100 }
            PathAttribute { name: "itemscale"; value: 1 }

            PathLine {
                x: app.width
                y: app.height * 0.5
            }

            PathAttribute { name: "z"; value: 0 }
            PathAttribute { name: "itemscale"; value: 0.5 }
        }
    }
}

此代码生成此渲染:

路径上的项目明显依附于它们的垂直中心,没有明确指出是否也涉及水平中心。

现在我想将项目放置在路径的顶部,即矩形应该底部对齐,底部边框位于屏幕中央。换句话说,我想通过底部锚点而不是中心来附加它们。

Qt 文档在那里没有太大帮助。我能否在没有恶意黑客攻击的情况下完成此操作?如果可以,我该怎么做?

你的问题是由规模引起的,如果我们评论那一行,我们会得到以下内容:

观察到对齐了。比例尺使用称为 transformOrigin 的参考点,默认情况下是项目的 Item.Center,在您的情况下,它应该是 Item.Bottom.

进行以下更改:

delegate: Rectangle {
    id: item
    height: app.height * 0.5
    width: app.width * 0.25
    y:0

    border.width: 5
    border.color: "#2f2f2f"
    color: "#d2d2d2"

    scale: PathView.itemscale
    transformOrigin: Item.Bottom // +++
    z: PathView.z
}

得到: