我的窗口中有一个文本元素,我希望它每隔几秒钟或几毫秒闪烁或出现和消失一次。
我的代码是:
import QtQuick 2.6
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Text {
id: my_text
text: "Hello"
font.pixelSize: 30
}
}
该
任务很容易用Timer
解决。
import QtQuick 2.6
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Text {
id: my_text
font.pixelSize: 30
text: "Hello"
}
Timer{
id: timer
interval: 1000
running: true
repeat: true
onTriggered: my_text.opacity = my_text.opacity === 0 ? 1 : 0
}
}
另一种使用 OpacityAnimator
的解决方案:
import QtQuick 2.6
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Text {
anchors.centerIn: parent
id: my_text
text: "Hello"
font.pixelSize: 30
OpacityAnimator {
target: my_text;
from: 0;
to: 1;
duration: 400;
loops: Animation.Infinite;
running: true;
easing {
type: Easing.InOutExpo;
}
}
}
}