2016-07-27 1 views
1

Rectangle을 사용하여 만든 카드가 있다고 가정 해 보겠습니다. 클릭 할 때 버튼 위에 표시하고 싶습니다. 나는 그 일을 위해 showMenu() 함수를 호출하고 있는데, 나는 ListView을 동적 인 ListModel과 함께 사용하고있다. 이러한 문제는 버튼이 상단 대신에 Rectangle 아래에 추가 된 것입니다. 항목을 모델에 추가 한 후 앵커가 업데이트되지 않습니다. 여기 내 코드가ListView 동적 앵커링

Item { 
    width: 120 
    height: 120 
    Rectangle { 
     id: card 
     width: 50 
     height: 100 
     color: "pink" 
     anchors.bottom: parent.bottom 
     Item { 
      id: rec 
      width: 50 
      anchors.bottom: parent.top // This anchor is not updating after appending an item to the list. 

      ListModel { 
       id: menuListModel 
      } 

      Component { 
       id: delegate 
       Rectangle { 
        width: 120 
        height: 20 
        color: "blue" 
        Text { 
         anchors.fill: parent 
         anchors.centerIn: parent 
         text: commandText 
        } 
       } 
      } 

      ListView { 
       anchors.fill: parent 
       model:menuListModel 
       delegate: delegate 
       interactive: false 
      } 
     } 

     MouseArea { 
      anchors.fill: parent 
      onClicked: menuListModel.append({"commandText" : "Normal Summon"}); 
     } 
    } 
} 
+0

실행할 코드를 게시 할 수 있습니까? – Mitch

+0

이 예제를 업데이트했습니다. –

답변

0

이것은 다소 중복의 this question입니다. Item에는 height이 필요합니다. 이 질문에 대한 답에서 언급했듯이 이런 일이 생길 때 코드에 디버그 문을 추가 할 수 있습니다. 이 상황에서, 당신은 또한 Item의 자식으로 Rectangle을 추가하고 볼 수 있다고 확인 할 수 있습니다

Rectangle { 
    anchors.fill: parent 
    color: "transparent" 
    border.color: "darkorange" 
} 

을가 보이지 않는 경우에, 당신은 문제가 (부모) 항목에있는 것을 알고있다.

+0

높이를 추가하면 현재 예제가 해결되지만 내 코드에서는 높이가 동적이므로 개체가 모델에 추가 될 때마다 높이를 계속 업데이트해야합니까? 또는'ListView'의 높이가 아래쪽에서 위쪽으로 업데이트되는 방법이 있습니까? –

+0

그래서 항목의 높이는'ListView'의 높이에 달려 있습니까? – Mitch

+0

예'Item '의 높이는 ListView의 높이에 따라 다릅니다. –

관련 문제