diff options
author | Mitch Curtis <[email protected]> | 2024-06-19 16:24:31 +0800 |
---|---|---|
committer | Mitch Curtis <[email protected]> | 2024-06-21 15:07:15 +0800 |
commit | cb0dcd78b1f7059e0c5af761960a378e0274c571 (patch) | |
tree | fbdc44b39c39a2748c7e5fd6170b8e3285026740 | |
parent | 51381c2aeb2d432d1fc9dc5cd7b469aab9561de8 (diff) |
Document that properties in functions used as bindings will be re-evaluated
This was not obvious to me, so documenting it may help others out.
Pick-to: 6.8 6.7 6.5
Change-Id: I11f985627d6168ad9a808c450c694de3ca72bcfb
Reviewed-by: Ulf Hermann <[email protected]>
-rw-r--r-- | src/qml/doc/snippets/qml/function-call-binding.qml | 18 | ||||
-rw-r--r-- | src/qml/doc/src/qmllanguageref/syntax/propertybinding.qdoc | 7 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/qml/doc/snippets/qml/function-call-binding.qml b/src/qml/doc/snippets/qml/function-call-binding.qml new file mode 100644 index 0000000000..1dc7d0224c --- /dev/null +++ b/src/qml/doc/snippets/qml/function-call-binding.qml @@ -0,0 +1,18 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick + +//! [rectangle] +Rectangle { + x: rectPosition() + y: rectPosition() + width: 200 + height: 200 + color: "lightblue" + + function rectPosition() { + return enabled ? 0 : 100 + } +} +//! [rectangle] diff --git a/src/qml/doc/src/qmllanguageref/syntax/propertybinding.qdoc b/src/qml/doc/src/qmllanguageref/syntax/propertybinding.qdoc index 65e3b95f8e..b45ad83fb8 100644 --- a/src/qml/doc/src/qmllanguageref/syntax/propertybinding.qdoc +++ b/src/qml/doc/src/qmllanguageref/syntax/propertybinding.qdoc @@ -98,6 +98,13 @@ In the previous example, \li \c bottomRect.color depends on \c myTextInput.text.length \endlist +In addition, any properties referenced within a JavaScript function that is +itself used as a binding will be re-evaluated. For example, in the snippet +below, whenever the \c enabled property of the \c Rectangle changes, the +bindings for the \c x and \c y properties will be re-evaluated: + +\snippet qml/function-call-binding.qml rectangle + Syntactically, bindings are allowed to be of arbitrary complexity. However, if a binding is overly complex - such as involving multiple lines, or imperative loops - it could indicate that the binding is being used for more than describing |