Each predefined QML type has a set of predefined properties that you can specify values for. You can add custom properties that would not otherwise exist for a particular type. You bind the properties to dynamic expressions to define global properties for an object that can be read by other objects. For example, you can specify global properties for the root object that you can use in the child objects.
For example, to specify spacing between UI elements, you could define a margin for an object of a QML type that does not have a margin property, and then use bindings to refer to the value of the margin property from other objects.
Similarly, you can add custom properties for your own QML types that are based on the predefined types.
You can add properties for objects in the Connections view, 特性 tab.
To add properties for an object:
(
Add
) button to add a dynamic property for the currently selected item. The item ID is displayed in the
Item
column.
Right-click a property and select Open Binding Editor in the context menu to bind the value of the property to that of another one or to data accessible in the application in Binding Editor 。更多信息,见 Setting Bindings .
The properties you add for a QML type are displayed in the 特性 view when you select a component of that type in Navigator or Form Editor .
For more information about setting property values in the 特性 view, see Specifying Item Properties .
For an example of using custom properties in an application, see 创建移动应用程序 .
The following table describes the supported property types:
| Type | 描述 |
|---|---|
| alias | Property alias that holds a reference to another property |
| bool |
Binary
true
or
false
value
|
| color | Color value that can be specified by using an SVG color name, such as "red", "green", or "lightsteelblue", or a hexadecimal triplet or quad in the form "#RRGGBB" and "#AARRGGBB", respectively. For example, the color red corresponds to a triplet of "#FF0000" and a slightly transparent blue to a quad of "#800000FF". In addition, you can use the following Qt functions: Qt.rgba() , Qt.hsva() , Qt.hsla() , Qt.darker() , Qt.lighter() ,和 Qt.tint() . |
| int | Whole integer number, such as 0, 10, or -20 |
| real | 带小数点的数字 |
| string | 自由形式文本字符串 |
| url |
Resource locator, such as a file name. It can be either absolute, (
http://qt-project.org
), or relative (
pics/logo.png
). A relative URL is resolved relative to the URL of the parent component.
|
| variant | Generic property type. For example, variant properties can store numbers, strings, objects, arrays, and functions. |