QML : Binding loop detected (MWE)
Есть два Rectangle: rectParent и rectChild:
rectParentимеет длину и ширину на 10 пикселей больше, чем уrectChild, причем уrectChildстороны заданы жесткоrectChildнаходится по центруrectParent
Логично, что rectParent для вычисления своих размеров обращается к rectChild, который, в свою очередь, обращается к rectParent для вычисления анкеров.
Но rectParent.height вычисляется исключительно из rectChild.height, которые заданы жестко. И потом из rectParent.height (и координат, на которые дочерний объект не влияет) вычисляется rectChild.verticalCenter.
Вопрос: откуда взялся цикл (хотя отображается всё корректно) и как всё же сделать по фен-шую?
QML MWE:
import QtQuick
Window {
visible: true
title: qsTr("mve")
Rectangle {
id: rectParent
color: "#bbb"
width: childrenRect.width + 10
height: childrenRect.height + 10
Rectangle {
id: rectChild
width: 200
height: 50
color: "#ddd"
anchors {
horizontalCenter: parent.horizontalCenter
verticalCenter: parent.verticalCenter
}
}
}
}
Warnings:
qrc:/qt/qml/CenterTheDiv/Main.qml:11:9: QML Rectangle: Binding loop detected for property "height"
qrc:/qt/qml/CenterTheDiv/Main.qml:11:9: QML Rectangle: Binding loop detected for property "height"
qrc:/qt/qml/CenterTheDiv/Main.qml:10:9: QML Rectangle: Binding loop detected for property "width"