如何获取有关 ColumnLayout 内部元素的笛卡尔坐标

How to get cartesian coordinates about element inside of ColumnLayout

有一个 ColumnLayout,里面有 4 个不同的项目,使用 Layout 定位,我如何从这些项目之一获得笛卡尔坐标?

示例:

import QtQuick 2.11
import QtQuick.Layouts 1.3

ColumnLayout {
    spacing: 0
    Layout.topMargin: 10
    Layout.bottomMargin: 10

    Image {
        id: item1 
        Layout.alignment: Qt.AlignHCenter
        sourceSize: Qt.size(204, 96)
    }

    Text {
        id: item2
        Layout.topMargin: 15
        Layout.fillWidth: true
        horizontalAlignment: Text.AlignHCenter
        text: "hello"

    }

    Text {
        id: item3
        Layout.alignment: Qt.AlignHCenter
        text: "world"
    }
}

id 为 "item3" 的元素的笛卡尔坐标位置是多少?如何获得?

如果您想获得 item3 相对于 ColumnLayout 的位置,您必须使用属性 x, y:

// ...

Text {
    id: item3
    Layout.alignment: Qt.AlignHCenter
    text: "world"
    Component.onCompleted: console.log(x, y)
}

如果您想尊重屏幕,您必须使用 mapToGlobal() 功能:

Component.onCompleted: console.log(mapToGlobal(x, y))