Как рассчитать высоту нижнего колонтитула, которая будет разницей между ListView.height и суммой высоты видимых элементов - PullRequest
0 голосов
/ 27 февраля 2019

У меня есть 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()
        }
    }
}

Как я могурешить эту проблему?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...