如何计算页脚高度,该高度将是ListView.height与可见元素的高度之和之间的差

时间:2019-02-27 08:16:32

标签: qt qml

我有ListView,我想在其中的滚动区域顶部放置元素

enter image description here

我尝试通过添加页脚进行操作

enter image description here

并且我尝试计算页脚高度,但得到错误: qrc:/main.qml:28:17:QML项目:检测到属性“ height”的绑定循环

import QtQuick 2.3
import QtQuick.Controls 1.2

ApplicationWindow {
    visible: true
    width: 640
    height: 480

    ListView {
        id: list
        anchors.fill: parent
        model: 50
        cacheBuffer:1000
        delegate: Rectangle {
            id: dg
            property int yoff: Math.round(dg.y - list.contentY)
            property bool isFullyVisible: (yoff > list.y && yoff + height < list.y + list.height)
            border.color: Qt.darker(color, 1.2)
            color: isFullyVisible ? "#ccffcc" : "#fff"
            height: /*Math.random() **/ 100
            width: parent.width
            Text {text: "Fully visible: " + isFullyVisible + " dg.y: " + dg.y + " list.contentY: " +
                        list.contentY + " list.y: " + list.y + " list.height: " + list.height +
                        " dg.height: " + dg.height
                anchors.centerIn: parent}
        }

        footer: Item {
            id: ft

            function calculateFooterHeight(){

                var sumHeightOfVisibleElements = 0

                for(var child in list.contentItem.children) {
                    sumHeightOfVisibleElements += list.contentItem.children[child].height
                }

                    return sumHeightOfVisibleElements
            }

            width: parent.width
            height: list.height - calculateFooterHeight()
        }
    }
}

如何解决此问题?

0 个答案:

没有答案