Created
March 16, 2023 05:35
-
-
Save FONQRI/67367fa28bc5267649a1e102e9d4c2dc to your computer and use it in GitHub Desktop.
QMLECMAScriptExample.qml for https://moderncpp.ir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Text | |
{ | |
id: label | |
x: 24; y: 24 | |
// custom counter property for space presses | |
property int spacePresses: 0 | |
text: "Space pressed: " + spacePresses + " times" | |
// (1) handler for text changes | |
onTextChanged: console.log("text changed to:", text) | |
// need focus to receive key events | |
focus: true | |
// (2) handler with some JS | |
Keys.onSpacePressed: { | |
increment() | |
} | |
// clear the text on escape | |
Keys.onEscapePressed: { | |
label.text = '' | |
} | |
// (3) a JS function | |
function increment() { | |
spacePresses = spacePresses + 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment