QT从一个文本框回车跳到下一个文本框

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 MainWindow::next()
{
    QLineEdit *lineEdit = (QLineEdit *)sender();
    if (lineEdit == ui->lineEdit) {
        ui->lineEdit_2->setFocus();
    } else if (lineEdit == ui->lineEdit_2) {
        ui->lineEdit_3->setFocus();
    } else if (lineEdit == ui->lineEdit_3) {
        ui->lineEdit->setFocus();
    }
}
posted @ 2021-12-21 14:36  江南王小帅  阅读(557)  评论(0)    收藏  举报