Qt lineEdit使用回车跳转到下一个lineEdit

定义lineEdit类,继承QLineEdit,如下:
class lineEdit : public QLineEdit
{
Q_OBJECT
signals:
void next(); //连接要跳转的下一个lineEdit控件
private slots:
void nextLE(); //连接returnPress()信号,触发next()信号
};

代码片段:

lineEdit *lineEdit_OR = new lineEdit(); 
connect(lineEdit_OR,SIGNAL(returnPressed()),lineEdit_OR,SLOT(nextLE()));
lineEdit *lineEdit_RFCB = new lineEdit();
connect(lineEdit_RFCB,SIGNAL(returnPressed()),lineEdit_RFCB,SLOT(nextLE()));
lineEdit *lineEdit_RBCB = new lineEdit();
connect(lineEdit_RBCB,SIGNAL(returnPressed()),lineEdit_RBCB,SLOT(nextLE()));
lineEdit *lineEdit_SCMD = new lineEdit();
connect(lineEdit_SCMD,SIGNAL(returnPressed()),lineEdit_SCMD,SLOT(nextLE()));
lineEdit *lineEdit_PSIB = new lineEdit();
connect(lineEdit_PSIB,SIGNAL(returnPressed()),lineEdit_PSIB,SLOT(nextLE()));
lineEdit *lineEdit_PSMD = new lineEdit();
connect(lineEdit_PSMD,SIGNAL(returnPressed()),lineEdit_PSMD,SLOT(nextLE()));
QDialog *w = new QDialog;connect(lineEdit_OR,SIGNAL(next()),lineEdit_RFCB,SLOT(setFocus()));
connect(lineEdit_OR,SIGNAL(next()),lineEdit_RFCB,SLOT(setFocus()));
connect(lineEdit_RFCB,SIGNAL(next()),lineEdit_RBCB,SLOT(setFocus()));
connect(lineEdit_RBCB,SIGNAL(next()),lineEdit_PSIB,SLOT(setFocus()));
connect(lineEdit_PSIB,SIGNAL(next()),lineEdit_PSMD,SLOT(setFocus()));
connect(lineEdit_PSMD,SIGNAL(returnPressed()),w,SLOT(accept()));

你可能感兴趣的:(C++)