2015-08-28 49 views
0

我使用listview创建了一个qml列表,我需要列表高度,但是当我尝试使用List.height获取列表高度时,输出为零。但count和contentHeight正常。请建议如何继续,请找到下面的代码。QML列表视图高度问题

Rectangle{ 
     id:displayarea 
     anchors.top:subTitle.bottom 
     anchors.margins: 5 
     width: parent.width-8 
     height: parent.height-30 
     x:4 
     anchors.topMargin: 2 
     Image { 
      id: fileInfoImage 
      width: parent.width 
      height: parent.height-15 
      source: Model.imagePath+Model.imageName 
      fillMode: Image.PreserveAspectFit 
     } 
     listView { 
      id: list 
      spacing: 1 
      interactive: true 
      width: parent.width 
      focus: true 
      anchors { 
       left: recstring.left; 
       top: fileInfoImage.bottom; 
       rightMargin: 1 
       topMargin: 2; 
       right: scrollBar.left 
      } 
      delegate: listDelegate 
      model: MainModel 
      cacheBuffer: 50 
      onContentHeightChanged: { 
       console.log("scrollbar visibility",scrollBar.visible,list.height,list.contentHeight,height); 
       scrollBar.visible = list.height 
         < list.contentHeight 
       thumb.height = list.height 
         /(list.contentHeight/list.height) 
       console.log("thumb height",thumb.height,list.height); 
      } 
     } 
     Component{ 
      id: listDelegate 
      Item{ 
       width: parent.width 
       implicitHeight: descriptionText.implicitHeight 
       Rectangle{ 
        id: faultCode 
        width: scrollBar.visible ? recstring.width-10 : recstring.width-7; 
        height: parent.height 
        Text{ 
         id:descriptionText 
         width:parent.width 
         text:(strType == 1)?(" \u2022 " +qsTr(disString)):qsTr(disString) 
         wrapMode: Text.Wrap 
         font.pixelSize: (text.length === 0) ? 2: 8 
         anchors { 
          margins: 1; 
         } 
        } 
       } 
      } 
     } 

回答

1

ListView高度属性不明确定义(即使不是全部定义)。 因此定义height属性。 或者,您可以尝试定义ListView锚的bottom属性。

了一句话:你ListView的ID无效:

ID不能以大写字母开头(M14)

+0

谢谢,工程.... – user3049522

+0

不客气: ) –