slint
slint copied to clipboard
Add a gained_focus / lost_focus callbacks to FocusScope
It would be useful to be able to run arbitrary code when a focussable element gains focus / loses. My use case is replacing a "passive" widget with an "active" (editable) one when it gets focus.
Thanks for the suggestion. Some discussion about this also hapenned in https://github.com/slint-ui/slint/issues/1206
Regarding your use case, maybe you can just do
if (focus_scope.has-focus) : MyEditableWidget {
//...
}
Thanks for the suggestion, here is an example of what I'm trying to do. It works if you click on the message to start editing, the Text is replaced with the TextInput. I'd like the user to be able to give the focus to the Text, and then have the Text be replaced by the (focussed) TextInput.
I presume the solution with an if won't work, since i needs to exist so that t can give it the focus.
export Demo := Window {
property<bool> editing: false;
property<string> greeting: "Click to edit!";
t := Text {
text: root.greeting;
font-size: 24px;
visible: !root.editing;
callback activated;
activated => {
i.text = root.greeting;
root.editing = true;
i.focus();
}
TouchArea {
clicked => { parent.activated() }
}
// FocusScope {
// gained-focus => { parent.activated() }
// }
}
i := TextInput {
text: root.greeting;
font-size: 24px;
color: purple;
visible: root.editing;
accepted => {
root.greeting = self.text;
root.editing = false;
}
}
}
Maybe have a generic way to react to property changes?
I am still not sure what you actually want to achieve here:-(
Fixed with https://github.com/slint-ui/slint/pull/3650