#ifndef GOTODIALOG_H
#define GOTODIALOG_H
#include <QtGui>
#include "ui_gotodialog.h"
class gotodialog : public QDialog, public Ui::GoToCellDialog
{
Q_OBJECT
public:
gotodialog(QWidget *parent = 0, Qt::WFlags flags = 0);
~gotodialog();
private:
// 命名符合 on_objectName_signalName(),
// setupUi会自动建立connect(lineEdit,SIGNAL(textChanged(const QString &)), this, SLOT(on_lineEdit_textChanged()));
void on_lineEdit_textChanged();
};
#endif // GOTODIALOG_H
#include "gotodialog.h"
gotodialog::gotodialog(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
// 初始化窗体
setupUi(this);
// 检验器,控制输入:允许一个大写或小写字母,
// 后面跟一个范围是1~9的数字,后面再跟0个、1个或2个0~9的数字
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp, this));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}
gotodialog::~gotodialog()
{
}
void gotodialog::on_lineEdit_textChanged()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
#include "gotodialog.h"
#include <QtGui/QApplication>
#include <QtGui/QDialog>
#include "ui_gotodialog.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
gotodialog *dialog = new gotodialog;
dialog->show();
return a.exec();
}