2012-05-22 2 views
0

내가 예를 들어, 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 
    } 
} 

내가 원하는 것은 (mousearea 인 구조를 변경하지 않고 drag.target에 대한 바인딩, anchors.fill 일을하는 것입니다 형제 자매 나 대상이 아닙니다.) 나는 Binding 함수를 사용하여 thetarget을 반환했지만 모두 쓸모가 없습니다. 누군가 나에게 무엇이 잘못되었는지 말해 줄 수 있습니까?

+0

나는 왜 당신이 컨테이너 아래에 넣고 thetarget에 바인딩하려는 이유는 대상 요소 아래에 MouseArea를 넣어 야한다고 생각하니? – Kunal

+0

독립된 구성 요소를 만들고 항목 (예 : thetarget)을 API에 전달하려고합니다. 해당 구성 요소는 전달 된 항목을 드래그하는 데 사용할 수있는 MouseArea가 포함 된 Item, Loader 또는 Rectangle ... 일 수 있습니다. –

답변

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

이것은 내가 필요한 것입니다. 고맙습니다! –