gpt4 book ai didi

qt - 如何让QT文本每隔几毫秒出现一次(闪烁)

转载 作者:行者123 更新时间:2023-12-02 17:15:06 29 4
gpt4 key购买 nike

我的窗口中有一个文本元素,我希望它每隔几秒或几毫秒闪烁一次或出现并消失。

我的代码是:

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
}
}

关于qt - 如何让QT文本每隔几毫秒出现一次(闪烁),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46796231/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com