本篇文章是对来自🤝BiliBili-清晨与猫鱼的QML教程的学习笔记,原视频链接👇
https://www.bilibili.com/video/BV1Ay4y1W7xd?spm_id_from=..search-card.all.click&vd_source=4079f59f2068471b4d379822052e0270


自定义QML组件

新建QML文件-TimerDateLabel.qml

1
2
3
4
5
6
7
8
9
10
import QtQuick 2.14
import QtQuick.Controls 1.4

Label {
id:label
Timer {
interval: 500; running: true; repeat: true
onTriggered: label.text = Date().toString()
}
}

main.qml中调用TimerDateLabel.qml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 1.4

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

Item{
anchors.fill: parent

Column{
TimerDateLable{
color: "red"
}
TimerDateLable{
color: "blue
}
}

}
}

QML自定义组件