QML好处:跨平台移植性、开发的开放性、开发者效率
1、QML语言提供基本数据类型:date 、size、 opint、 rect、color、font。还有基本对象类型:String Date、Timer等。
QT Quick子模块:Window、Layouts、Dialogs、XML、List、Mode1
2、每个QML文档由两部分组成
import(导入需要的Qt Quick库),比如import QtQuick2.3
对象声明:是QML程序主体部分
3、QML基本语法
对象和属性:以大写字母开头,后面跟一对大括号{},{}之中是该对象的属性,属性以键值对”属性名:值“的形式
对象标识符:每个对象都可以指定一个唯一的id值,这样便可以在其他对象中识别并引用对象
4、注释QML文档注释同C/C++、JavaScript代码注释一样:
(1)单行注释使用"//"开始,在行末尾结束
(2)多行注释使用"/*"开始,使用"*/"结尾
5、QML元素
a.Image(图像元素)
添加图标
b.Rectangle(矩形元素)
c.Text(文本元素)
d.Button(按钮元素)
e.BusyIndicator(繁忙指示器)
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.3
import QtGraphicalEffects 1.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
BusyIndicator
{
id:mybusuIndicator
//anchors:瞄点布局
anchors.centerIn: parent //把子类的控件放到父类的中心
implicitWidth: 200
implicitHeight: 200
contentItem: Item {
Rectangle{
id:myrect
width:parent.width
height: parent.height
color: Qt.rbra(0,0,0,0)
radius: width/2
border.width: width/8//数字越大圆圈越小
visible: false;//边框是否见
}
ConicalGradient
{
width: myrect.width
height: myrect.height
gradient: Gradient
{
GradientStop{position: 0.0;color:"chartreuse"}//圆圈颜色
GradientStop{position: 1.0;color:"orange"}//跟踪圆圈旋转后的颜色
}
source: myrect
Rectangle{
anchors.top:parent.top
anchors.horizontalCenter: parent.horizontalCenter
width: myrect.border.width
height: width
radius:width /2
color:"red"
}
RotationAnimation on rotation {
from: 0
to:360
duration: 2000
loops: Animation.Infinite//循环
}
}
}
}
}