Basic elements of qml

Item

Item (basic element object) is usually used as a container for other elements, similar to the div element in HTML.

rectangle

    Rectangle{
        id:rect
        width: 800
        height: 400
        color: "slategray"
    }

Insert picture description here

Gradient

    Rectangle{
        id:rect
        width: 800
        height: 400
        gradient: Gradient{
            GradientStop{ position: 0.0; color: "lightsteelblue" }
            GradientStop{ position: 1.0; color: "slategray" }
        }
    }

Insert picture description here

Text element

    Text {
        id: text
        text: qsTr("text")
        color: "#303030"
        font.family: "Ubuntu"
        font.pixelSize: 28
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
    }

Insert picture description here

image

Image {
    id: image
    width: 500
    height: 300
    source: "images/background.png"
}

Insert picture description here

⿏MouseArea Element

Rectangle{
    id: root
    width: 500
    height: 300
    color: "#b0c4de"
    MouseArea{
        id: area
        width: parent.width
        height: parent.height
        onClicked: {
            if(root.color == "#b0c4de")
            {
                root.color = "#708090"
            }
            else
            {
                root.color = "#b0c4de"
            }
        }
    }
}

Guess you like

Origin blog.csdn.net/sinat_33859977/article/details/115036204