【问题标题】:QML listview height issueQML列表视图高度问题
【发布时间】:2015-08-28 18:36:05
【问题描述】:

我使用 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;
                        }
                    }
                }
            }
        }

【问题讨论】:

    标签: c++ qml


    【解决方案1】:

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

    备注:您的ListView id 无效:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 2013-07-26
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 2020-01-30
      • 2017-01-16
      相关资源
      最近更新 更多