2014-12-09 2 views
1

나는 내가 원하는 것을하지 못하게하는 이상한 행동을 발견했습니다.Flickable + 속성 별칭 내용

내가

Comp.qml있는 경우 :

Rectangle { 
    id: comp; 
    anchors.fill: parent 

    default property alias contents: flickable.children; 
    property int contentHeight: comp.height; 

    Flickable { 
     id: flickable; 
     anchors.fill: parent; 
     contentHeight: comp.contentHeight; 
    } 
} 

main.qml을 :

Rectangle { 
    id: root; 
    width: 400; 
    height: 400; 

    Comp { 
     contentHeight: 800; 
     Rectangle { 
      width: 800; 
      height: 800; 
      border.color: "black"; 
      border.width: 5; 
      Component.onCompleted: console.debug(parent) 
     } 
    } 
} 

flickable 한이 작동하지 않습니다.

main.qml :

Rectangle { 
    id: root; 
    width: 400; 
    height: 400; 

    Rectangle { 
     id: comp; 
     anchors.fill: parent 

     Flickable { 
      id: flickable; 
      anchors.fill: parent; 
      contentHeight: 800; 

      Rectangle { 
       width: 800; 
       height: 800; 
       border.color: "black"; 
       border.width: 5; 
      } 
     } 
    } 
} 

난 실종 뭔가를 예상대로

나는 하나 개의 파일에 모든 것을 넣어하려고하면

, 그것은 작동?

콘텐츠가 flickable에있는 외부 구성 요소를 수행하는 방법은 무엇입니까? docs에 명시된 바와 같이

+0

그것은이 초기화되기 전에 flickable 한을 QML 바인드 어린이 항목에 비해 보인다. 'comp'에서'onContentsChanged : {flickable.contentWidth}'를하면 * -1 *을 얻을 것입니다. 그러나이 '사각형'은 800px 너비입니다. 그래서 그것이 크기 문제 wile reparenting일지도 모른다. – folibis

답변

2

하십시오 flickable 한의 자식으로 선언

항목이 자동으로 flickable 한의 의 ContentItem에 을 부모가된다. 동적으로 생성 항목을 명시 적으로 RectangleFlickable에 자신을 부모가있어 및 예상되는 동작을 노출하지 않습니다 즉 여기 처음이 아니다 년대의 ContentItem

에을 부모가 해야합니다. 아마도, children에 추가해도 정확한 양육을 유발하지 않습니다. 빠른 수정으로 Comp 유형에 추가되는 즉시 항목의 부모를 다시 지정할 수 있습니다.

Comp 안에 여러 개의 Item을 처리하려면 고유 한 하위 항목 (라 ScrollView)을 사용하십시오. 여기서는 두 개의 Rectangle (예 : ~ Comp)을 처리하도록 예제를 수정했습니다.

주에서

다음 Comp.qml 파일에서

Rectangle { 
    id: root; 
    width: 400; 
    height: 400; 

    Comp { 
     contentHeight: col.height; 

     Column { 
      id: col 
      spacing: 20 
      Rectangle { 
       width: 800; 
       height: 800; 
       border.color: "black"; 
       border.width: 5; 
      } 

      Rectangle { 
       width: 800; 
       height: 800; 
       border.color: "black"; 
       border.width: 5; 
      } 
     } 

     Component.onCompleted: console.debug(col.parent) // <-- not flickable 
    } 
} 

:

Rectangle { 
    id: comp; 
    anchors.fill: parent 
    default property alias contents: flickable.children; 
    property int contentHeight: comp.height; 

    Flickable { 
     z:1 
     clip: true  // just my taste! 
     id: flickable; 
     anchors.fill: parent; 
     contentHeight: comp.contentHeight; 
    } 

    onContentsChanged: {        // re-parenting 
     if(flickable.children[1] !== undefined) 
      flickable.children[1].parent = flickable.contentItem 
    } 
} 
+1

고마워요, contentsChanged를 완벽하게 잘 작동합니다. – BlueMagma