首页 文章

QML绑定项目问题

提问于
浏览
0

我在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的兄弟或孩子) . 我使用了Binding,函数来返回目标,但它们都没用 . 有人能告诉我什么是错的吗?

1 回答

  • 3

    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
            }
        }
    }
    

相关问题