liudianwu |
2020-06-10 09:13 |
Qt开源作品32-文本框回车焦点下移
## 一、前言 这个demo由于太过简单,而不用过多的文字描述,其实就是实现了在一个文本框中输入完成以后,回车自动跳入下一个文本框,焦点下移,这个在很多的社保系统、医疗系统等系统中很常用,因为那些系统需要很多输入的地方,最快捷的方法就是输入完成以后回车跳入下一个输入框,这样用户不需要去用鼠标单击来切换光标焦点,在我们平时使用电脑的过程中,鼠标+键盘配合,效率是最高的,比如在编写代码过程中,需要把乱七八糟的代码格式化一下,看起来心情也好了很多,此时直接用快捷键会非常方便的,而不是使用鼠标去选择菜单。
## 二、代码思路 ```c++ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); connect(ui->lineEdit1, SIGNAL(returnPressed()), this, SLOT(next())); connect(ui->lineEdit2, SIGNAL(returnPressed()), this, SLOT(next())); connect(ui->lineEdit3, SIGNAL(returnPressed()), this, SLOT(next())); }
Widget::~Widget() { delete ui; }
void Widget::next() { QLineEdit *lineEdit = (QLineEdit *)sender(); if (lineEdit == ui->lineEdit1) { ui->lineEdit2->setFocus(); } else if (lineEdit == ui->lineEdit2) { ui->lineEdit3->setFocus(); } else if (lineEdit == ui->lineEdit3) { ui->lineEdit1->setFocus(); } } ```
## 三、效果图 [attachment=21668]
## 四、开源主页 **以上作品完整源码下载都在开源主页,会持续不断更新作品数量和质量,欢迎各位关注。**
1. 国内站点:[https://gitee.com/feiyangqingyun/QWidgetDemo](https://gitee.com/feiyangqingyun/QWidgetDemo) 2. 国际站点:[https://github.com/feiyangqingyun/QWidgetDemo](https://github.com/feiyangqingyun/QWidgetDemo) 3. 个人主页:[https://blog.csdn.net/feiyangqingyun](https://blog.csdn.net/feiyangqingyun) 4. 知乎主页:[https://www.zhihu.com/people/feiyangqingyun/](https://www.zhihu.com/people/feiyangqingyun/) |
|