Qt Quick-QML控件类-闪灯控件(支持动画)创作过程
本篇文章将讲述如何使用Qt Quick-QML控件类创建一个闪灯控件,该控件支持闪烁动画。
首先,我们需要创建一个QML文件并命名为BlinkingLight.qml。在该文件中,我们将定义一个矩形区域和一个圆形区域,用于表示灯的开和关状态。我们还将引入Qt Quick的动画组件,以便在灯亮起和灭掉之间过渡。
下面是BlinkingLight.qml的代码:
import QtQuick 2.15
import QtQuick.Controls 2.15
Rectangle {
id: container
width: 70
height: 70
Rectangle {
id: lightOn
color: "yellow"
radius: width/2
anchors.centerIn: parent
visible: false
}
Circle {
id: lightOff
color: "gray"
radius: width/2 - 5
anchors.centerIn: parent
visible: true
}
states: [
State {
name: "on"
PropertyChanges { target: lightOff; visible: false }
PropertyChan