QML 绑定项问题



我在 QML 中绑定项目时遇到问题,例如:

Rectangle{
    id: thetarget
    width:100
    height:100
}
Item{
    id: container
    MouseArea{            
        id:mousearea
        drag.target: thetarget  //not work        
        anchors.fill: thetarget  //not work
        property int foo: thetarget.width  //work
    }
}

我想要的是使 drag.target、anchors.fill 的绑定在不更改结构的情况下工作(鼠标区域不是目标的兄弟姐妹或子级)。我使用绑定函数返回目标,但它们都没用。有人可以告诉我出了什么问题吗?

mousearea的父级设置为 thetarget

import QtQuick 1.1
Item {
    Rectangle {
        id: thetarget
        width: 100
        height: 100
    }
    Item {
        id: container
        MouseArea {
            id: mousearea
            parent: thetarget
            drag.target: thetarget
            anchors.fill: thetarget
            property int foo: thetarget.width
        }
    }
}

最新更新