how to declare object in QML

QML file can have only one root object. and the root object is represented as a tree with children objects.

a object is declared by the object type and a set of curly braces. below code is a simple example declaring a object.


Item {
    width: 200
    height: 200
}

some attributes can be contained in the braces. in above example, width and height attributes are contained in Item object.

the way to declare children objects is like below.


Rectangle {
    width: 200
    height: 200
    color: "red"
    Rectangle {
        width: 100
        height: 100
        color: "blue"
        Rectangle {
            width: 50
            height: 50
            color: "black"
        }
    }
}




root is representing red box. and children objects are representing blue and black in sequence. if above example code is executed, you can see that image.

in above example,  each object has width, height and color. it looks like very simple. but if the size of project is big, the tree can be complicated more and attributes can be more than the example's attributes.





Comments

Popular posts from this blog

making menubar and menu on QML

let's start QML programming with PySide2

QSizePolicy Fixed example in pyside2