QML編程--學習Qt開發

前言 本講義代碼是使用Qt 6版本執行通過的,請大傢放心使用。 什麼是QML

我來參考翻譯一下: QML是一種Qt Meta-object Language的縮寫。它是一種聲明式編程語言,並且它是Qt框架的一個組成部分。QML的主要功能是讓開發人員快速、便捷地開發出用戶界面,這些界面包括瞭桌面應用、移動設備和嵌入式就用的界面。並且,QML還能夠與JavaScript無縫整合一起開發使用,即在QML代碼中可以直接使用JavaScript文件。 第一個Hello World

import QtQuick 2.9
import QtQuick.Window 2.2

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

Rectangle {
width: 360
height: 360
Rectangle{
id: button1

width: 100
height: 30
color: "red"
radius: 5
anchors.centerIn:parent

Text{
id: buttonText
text:qsTr("Button")
color:"white"
anchors.centerIn:parent
}

MouseArea{
anchors.fill:parent
onClicked:{
buttonText.text = qsTr("Clicked");
buttonText.color = "black";
}
}
}
}

Text{
id:text1
text: qsTr("Hello World")
anchors.left:button1.right
}

Image{
source:"nb.png"
anchors.centerIn:parent
}
}

赞(0)