Stop Button from stealing focus
-
Hello.
I can't figure out how to avoid buttons stealing focus in QML/QtQuick.
For example, suppose (simplified case) I have aTextFieldand aButton(Qt Quick Controls 2). Initially theTextFieldis focused for entry. Then, when the button is clicked, I do not want to remove focus from theTextField.How can stop the focus from changing when the
Buttonis clicked?
I understood that settingfocus: truerequests focus, but setting it tofalsedoesn't seem to stop focusing. I've tried to set it back to false ononActiveFocusChangedto no avail. Also, wrapping theButtonin aFocusScopewithfocus: falsedoesn't have any effect either: clicking the button still unfocuses theTextField.Appreciate any insight into how to solve the problem.
Thanks!(PS: In the actual application, any of many controls in the UI could have focus when the button is clicked and I'd like not to steal the focus from whichever is focused. Hence, solutions requiring keeping track of what is focused somehow are less desirable)
-
To answer my own question :)
Just add:
focusPolicy: Qt.NoFocus
to theButtonand the behaviour is as desired!