How to switch focus among 50 text fields in QML?

前端 未结 2 1730
旧时难觅i
旧时难觅i 2021-01-24 16:17

I want to switch focus from one field to the next when the user presses Enter: how would I go about it?

The items are arranged in a grid, as follows:



        
2条回答
  •  無奈伤痛
    2021-01-24 16:37

    Since TextField inherits from Item you can use the existing focus chain using nextItemInFocusChain(). Just add the following line to the TextField:

    Keys.onEnterPressed: nextItemInFocusChain().forceActiveFocus()
    

提交回复
热议问题