2014-06-08 4 views
4

QML 사용자의 디자인에서 reparent는 가능하지만 실제로 추가 할 수없는 상태를 만들고 변경하기 때문에 실제로 "구상"되지 않았습니다. 각 항목마다QML의 시각적 항목을 수정하는 더 나은 방법

import QtQuick 1.0 

Item { 
    width: 200; height: 100 

    Rectangle { 
     id: redRect 
     width: 100; height: 100 
     color: "red" 
    } 

    Rectangle { 
     id: blueRect 
     x: redRect.width 
     width: 50; height: 50 
     color: "blue" 

     states: State { 
      name: "reparented" 
      ParentChange { target: blueRect; parent: redRect; x: 10; y: 10 } 
     } 

     MouseArea { anchors.fill: parent; onClicked: blueRect.state = "reparented" } 
    } 
} 

불필요한 상태의 항목을 오염시키지 않으면 서 항목을 다시 만드는 더 우아한 방법이 있는지 궁금합니다.

답변

3

QtQuick 1.0을 사용해야하는 경우 확실하지 않지만 2.0을 사용하면이 기능이 작동하므로 훨씬 간단합니다.

 
import QtQuick 2.0

Item { width: 200; height: 100

Rectangle { id: redRect width: 100; height: 100 color: "red" } Rectangle { id: blueRect x: redRect.width width: 50; height: 50 color: "blue" MouseArea { anchors.fill: parent; onClicked: { blueRect.parent = redRect; blueRect.x = 10; blueRect.y = 10 } } } }

+0

'ParentChange' 실제로 (예 : root''등 내부적으로 볼 ID로) 자신의 파일에 독립 개체에 대해 작동하지 않습니다. 이 대답은 해당 시나리오에도 적용됩니다. –