Qml code specification

Source: Internet
Author: User

 

 

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.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.