On this page

Add bindings between properties

To dynamically change the behavior of a component, you can create a binding between the properties of two components. To create a property binding, a property is assigned a JavaScript expression that evaluates to the desired value. Behind the scenes, the variables in the binding expression are monitored. When a change is detected, the binding expression is re-evaluated and the new result is applied to the property.

At its simplest, a binding may be a reference to another property. For example, the height of a component can be bound to the height of its parent, so that when the parent height changes, the component height is adjusted automatically.

For more information about the use of property bindings, see Property Binding.

To create bindings between components, go to Connections > Bindings.

The Bindings tab in the Connections view.

Create bindings between component properties

To bind a property of a component to the property of another component:

  1. Place two components in the 2D view.

    Two components next to each other in the 2D view.

  2. Name the first component as viewBox.
  3. Name the second component as connectBox.
  4. Apply a thick black Border and a blue Color to the viewBox component.
  5. Select the connectBox component.
  6. Select Bindings from the Connections view.
  7. Select the the Plus button (Add) button to add a binding to the currently selected component in the binding editor.

    The binding editor.

    The binding editor.

  8. In From, select viewBox as the parent component. Then select its border.color property.
  9. In To, the connectBox component is already selected as the target component. Select color from the drop-down below to set its affected property.
  10. The border.color of the viewBox component is applied to the color of the connectBox component.

    Two components next to each other in the 2D view with the property binding applied.

All bindings have an automated JavaScript expression in the code. For more information, see Set bindings.

For an example of creating property bindings, see Use states to change component property values.

Summary of logical operators

You can use the following logical operators in the expressions to combine several conditions in one expression:

OperatorMeaningEvaluates to true if
!NOTThe condition is not met.
&&ANDBoth conditions are met.
||OREither of the conditions is met.
<Less thanThe left operand is less than the right operand.
>Greater thanThe left operand is greater than the right operand.
>=Greater than or equalThe left operand is greater than or equal to the right operand.
<=Less than or equalThe left operand is less than or equal to the right operand.
==EqualThe operands are equal.
===Strict equalThe operands are equal and of the same type.
!=Not equalThe operands are not equal.
!==Strict not equalThe operands are of the same type but not equal, or are of different type.

In addition, you can use arithmetic operators to compare numbers before checks. However, we recommend that you create separate properties for this purpose whenever possible.

See also How to: Use UI components, Qt Quick UI design, and Designing Qt Quick UIs.

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.