[Interest] Resolving QML binding loops?
Дмитрий Козлов
gnitry at mail.ru
Wed Jan 8 13:30:02 CET 2014
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 at 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
}
}
More information about the Interest
mailing list