[英]QML listview height issue
我已经使用listview创建了一个qml列表,我需要列表高度,但是当我尝试使用List.height来获取列表的高度时,输出为零。 但count和contentHeight正常显示。 请建议如何进行,请找到以下代码。
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;
}
}
}
}
}
您的ListView
height属性没有明确定义(甚至根本没有定义)。 因此,定义height
属性。 或者,您可以尝试定义ListView
锚点的bottom
属性。
备注:您的ListView
的ID无效:
ID不能以大写字母(M14)开头
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.