08.01.2014 16:10, Cornelius Hald пишет: > Hi, > > I was wondering if there are general patterns or best practices on how > to omit/resolve QML binding loops. > > For example, the following code does what it should do, but while > resizing the window I get a lot of warnings about the binding loop. > > Rectangle { > property double ratio: width / height > width: 600 > height: 300 > color: "gray" > > // Rectangle with a fixed aspect ratio centered in parent > Rectangle { > property double ratio: 1.6 > color: "red" > height: parent.ratio < ratio ? width / ratio : parent.height > width: parent.ratio > ratio ? height * ratio : parent.width > anchors.centerIn: parent > } > } > > How do others solve issues like this? > > Cheers, > Conny > > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest
I don't know about best practises, but I found this solution: Rectangle { property double ratio: width / height width: 600 height: 300 color: "gray" // Rectangle with a fixed aspect ratio centered in parent Rectangle { property double ratio: 1.6 color: "red" width: parent.ratio < ratio ? parent.width : parent.height * ratio height: width / ratio anchors.centerIn: parent } } _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest