Declarative UI is a way of making fluid user interfaces by describing them in terms of simple elements (Text, Image, Rect,and other QObjects) that are built up into components. The reason it is “declarative” is that rather than the changes in the UI being expressed as imperative code (”set this, set that, do this, do that, …”), they are instead expressed as sets of QObject property expressions (”this width is always half that width”), grouped into states (”when enabled, the properties are …, when disabled, they are …”). The language that enables this is named QML. QML is simple yet powerful. Most of a user interface is described by a simple tree structure of property bindings:
Code:
import Qt 4.6
Rectangle {
width: 200
height: 200
color: "white"
Text {
text: "Hello World"
anchors.centerIn: parent
}
}