Skip to content

Instantly share code, notes, and snippets.

@FONQRI
Created March 16, 2023 05:35
Show Gist options
  • Save FONQRI/67367fa28bc5267649a1e102e9d4c2dc to your computer and use it in GitHub Desktop.
Save FONQRI/67367fa28bc5267649a1e102e9d4c2dc to your computer and use it in GitHub Desktop.
QMLECMAScriptExample.qml for https://moderncpp.ir
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