When I click the button after 5 seconds it will turn green and then will return to its former color. I try to do it with timer function but it doesn't work. In QML Language
Asked
Active
Viewed 77 times
0
-
1Welcome to SO. Please add the code you've attempted to your question as a [mcve]. – Andy Aug 16 '22 at 11:33
-
PS If you want this in QML code you should remove the JavaScript tag. – Andy Aug 16 '22 at 11:58
1 Answers
0
This is just an example, but it's working using a Timer in QML:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
Window {
visible: true
width: 300
height: 300
Timer {
id: myTimer
interval: 5000; repeat: false
onTriggered: myButton.background.color = "blue"
}
Button {
id: myButton
x: 100
y: 100
text: "my button"
background: Rectangle {
color: "blue"
}
onClicked: {
myButton.background.color = "green"
myTimer.start();
console.log("clicked");
}
}
}

Tarod
- 6,732
- 5
- 44
- 50