如何在QML中的50个文本字段之间切换焦点? [英] How to switch focus among 50 text fields in QML?

查看:699
本文介绍了如何在QML中的50个文本字段之间切换焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户按下Enter时,我想将焦点从一个字段切换到下一个字段:我该如何处理?

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:

Grid {
  x: 5
  y: 3
  rows: 5
  columns: 20
  spacing: 10

  Repeater { 
    model: 50

    TextField { 
      width: 28
      height: 50
      color: "green"
      text: "0000"
      font.pixelSize: 12

      validator: IntValidator {
        bottom: -256
        top: 256
      }
    }
  }
}


推荐答案

由于 TextField 继承自 Item 您可以使用使用现有的焦点链 nextItemInFocusChain()
只需将以下行添加到 TextField

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()

这篇关于如何在QML中的50个文本字段之间切换焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆