QML Listview高度问题

用户名

我已经使用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;
                        }
                    }
                }
            }
        }
汤姆·阿玛克斯(Thom Armax)

您的ListViewheight属性没有明确定义(甚至根本没有定义)。因此定义height属性。或者,您可以尝试定义bottom属性ListView

备注:您ListView的ID无效:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章