1. Start
Import QT 4.7
The import declaration is to import QT modules that contain all standard qml elements.
2. Objects and attributes
In qml, an object is defined by an object type followed by a pair of curly brackets. In curly brackets, the object information is described, such as its attributes. properties are described in the form of property: value. The attributes and values are separated by colons. Each object has a unique ID attribute, which allows you to locate a specific object and perform related operations. Basic attributes include int, real, bool, String, color, and lists.
Attribute name: it usually starts with a lower-case character (except for additional attributes)
A id attribute
The ID must start with a lower-case letter or underline and cannot contain letters, numbers, or underscores. Each object can specify a special property called ID. The value of this property must be unique. The same ID value cannot be found in the same qml document. By specifying a unique available ID, the object can be referenced by other objects and scripts.
B list attribute
There are square brackets. The attributes in the list are separated by commas. Square brackets can be omitted if there is only one attribute.
C default properties
You can specify a list or object attribute as the default attribute for each object type. If an attribute has been declared as the default attribute, the label of this attribute can be omitted.
Group D attributes
In some examples, attributes constitute a logical group and are used by vertices (".") or group tags.
E Additional attributes
An additional attribute is used to attach some attributes to another object.
3. qml specifications
A. If the qml object statement is a separate expression
Rectangle {color: "Blue "}
B. If the qml object statement is multiple rows
Rectangle {
ID: rect
Width: 100; Height: 100
Color: "red"
}
4. qml Method for declaring property Variables
Property + class name + variable name: Value
For example, property int I: 2
5. Custom signal
For custom signals, the signal name must start with a lowercase letter. when responding to a custom signal, the signal name must start with the on + signal name, but the signal name must start with an uppercase letter.
6. Custom component Components
The component consists of a separate qml file name. The file name always starts with an uppercase letter. You can directly use this file name when using this component.
7. qml comments
The annotation method in qml is the same as that in Javascript.
Single line comment usage //;
Multi-line comment usage /*... */
8. Custom Components
The qml name of a custom component is generally capitalized, for example, button. qml. For reference to other files, you only need to directly reference the name.