QML (10) QML status

Source: Internet
Author: User

The user interface is used to display the interface in different scenes, or to change their appearance to the corresponding user's interaction. Typically, some column changes are concurrent. See the QML states keyword in QT help. The state attribute states.

1 Create Status

To create a status, you can add a state object to the project's States property, and the States property contains a list of the state of the project.

rectangle{        Id:window        width:240; height:150        color: "Red"        mousearea{        anchors.fill:parent OnClicked:window.state = "Moved"        }        states:[        state{            Name: "Moved"            propertychanges {                Target:window                x:50;y:50;}}        ]    }

In the example above, rectangle defaults to the (0 0) position, appends a moved state, and uses the Propertychanges object to change the position of the rectangle in order to (50 50). You can change the status by clicking it. The state project defines all the changes that are to be made in the new status, you can specify additional properties for the change, or you can create additional propertychanges for other zodiac, or modify the properties of other objects, not just the object that owns the state.

2 Default state

You can use states projects to process zodiac changes in batches. In addition, you can revert directly to the project default state. Use when to go back to the original state.

    rectangle{        Id:window        width:240; height:150        color: "Red"        mousearea{        Id:moousearea Anchors.fill:parent        }        states:[        state{            Name: "Moved";            when:moouseArea.pressed            propertychanges {                target:window                x:50;y:50;            }}        }    }}

Originally used onclicked () signal processor, call State switch. This is now implemented using the When property, which returns to the default state. You can also set property values directly.

    rectangle{        Id:window        width:240; height:150        color: "Red"        mousearea{        Id:moousearea Anchors.fill:parent        onPressed:window.state = "moved";        OnReleased:window.state = "";        }        states:[        state{            Name: "Moved";            propertychanges {                Target:window                x:50;y:50;            }}    }}

Using the When property is simpler than using the signal processor to allocate state, more declarative language, and the method of the When property is recommended.

QML (10) QML status

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.