先用 Qt Designer 设计,窗体的基本框架,然后进行编译
,以下是相关代码: gotocell.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #ifndef GOTOCELL_H #define GOTOCELL_H #include <QtGui/QDialog> #include "ui_gotocell.h" namespace Ui { class goToCellClass; } class goToCell : public QDialog,public Ui::goToCellClass { Q_OBJECT public: goToCell(QWidget *parent = 0); ~goToCell(); private slots: void on_lineEdit_textChanged(); private: Ui::goToCellClass *ui; }; #endif
|
gotocell.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #include<QtGui> #include "gotocell.h" #include "ui_gotocell.h" goToCell::goToCell(QWidget *parent) : QDialog(parent), ui(new Ui::goToCellClass) { ui->setupUi(this); QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}"); lineEdit->setValidator(new QRegExpValidator(regExp,this)); connect(okButton,SIGNAL(accepted()),this,SLOT(accept())); connect(cancelButton,SIGNAL(rejected()),this,SLOT(reject())); } goToCell::~goToCell() { delete ui; } void goToCell::on_lineEdit_textChanged() { okButton->setEnabled(lineEdit->hasAcceptableInput()); }
|
main.cpp
1 2 3 4 5 6 7 8 9
| #include <QtGui/QApplication> #include "gotocell.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); goToCell *dialog=new goToCell; dialog->show(); return app.exec(); }
|