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;
}
}
}
}
}
謝謝,工程.... – user3049522
不客氣: ) –