Qt学习之路 代码(6)几个控件的综合使用
首先编辑的设计界面如下
在头文件“dialog.h”加入:
private slots:
void on_lineEdit_textChanged();
在源文件“dialog.cpp”中加入:
#include "dialog.h"
#include "ui_dialog.h"
#include<QRegExpValidator>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
QRegExp regExp("[A-Za-z][1-9][0-9][0,2]");
//正则表达式限制输入子元的范围
ui->lineEdit->setValidator(new QRegExpValidator(regExp,this));
connect(ui->okButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(ui->cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
}
void Dialog::on_lineEdit_textChanged()
{
ui->okButton->setEnabled(ui->lineEdit->hasAcceptableInput());
}
Dialog::~Dialog()
{
delete ui;
}