qml1.qml

import QtQuick 2.0





Rectangle {

    id: rect

    color: "red"

    width: 360

    height: 360

    Text {

        anchors.centerIn: parent

        text: "Hello QML"

        font.pointSize: 24; font.bold: true

        color:  "lightgray"

    }

    function fun() {

    if(rect.color == "blue") {

    rect.color = "red"

    }

    else {

    rect.color = "blue"

    }

    }

    MouseArea {

        anchors.fill: parent

        onClicked: {

            fun()

        }

    }

}

 

你可能感兴趣的:(qml1.qml)