第一个QML程序

版本:Qt5.9.1javascript

QML是包含于Qt Quick的描述性语言。Qt Quick可使用QMLjava

指定项目名字,随便起windows

指定编译工具工具

qt5.4及以上,会提示是否创建对面的界面文件,能够选择,也能够不选择。ui

不使用版本控制系统3d

建立完成以后版本控制

清空main.qml,将其改为下面:code

import QtQuick 2.6
import QtQuick.Window 2.2

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle{
        width: parent.width/2
        height: parent.height/2
        color: "red"
        Text {
            id: title
            text: qsTr("hello world")
        }
    }
//    MainForm {
//        anchors.fill: parent
//        mouseArea.onClicked: {
//           Qt.quit();
//            // console.log(qsTr('Clicked on background. Text: "' + textEdit.text + '"'))
//        }
//    }
}

改进:orm

import QtQuick 2.6    //相似#include
import QtQuick.Window 2.2

Window {  //注册到Qt quick的对象
    visible: true
    width: 640
    height: 480   //建立640*480的windows对象
    title: qsTr("Hello World")

    Rectangle{
        width: parent.width/2
        height: parent.height/2  //widget&height是Rectangle的对象
        radius: 10   //圆角矩形
        color: "red"
        border.color: "black" //边界颜色
        border.width: 5       //边界宽度
        Text {  //Text能够经过Rectangle对象的子对象输出文本
            id: title
            color: "#00FF00"  //绿色
            text: qsTr("hello world")
            anchors.centerIn: parent  //将文本放在Rectangle的中间
        }

        MouseArea{   //处理鼠标事件
            anchors.fill: parent  //Rectangle
            onClicked: {   //鼠标点击
                Qt.quit(); //终止程序
            }
        }
    }
}

 

相关文章
相关标签/搜索