C++ GUI Qt4编程(05)-2.2GoToCell

1. 使用Qt设计师创建GoToCell对话框。

2. gotocelldialog.cpp

 

 1 #include <QRegExp>
 2 
 3 #include "gotocelldialog.h"
 4 
 5 GoToCellDialog::GoToCellDialog(QWidget *parent)
 6     : QDialog(parent)
 7 {
 8     setupUi(this);        /*初始化窗体*/
 9     /*setupUi()函数会自动将符合on_objectName_signalName()命名惯例的任意槽
10        与相应的objectName的signalName()信号连接到一起。*/
11     
12     /*{0,2}中2前面不能有空格,有空格的话,lineEdit框中无法输入*/
13     QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
14     /*QRegExpValidator检验器类*/
15     /*把this传递给QRegExpValidator的构造函数,使它成为GoToCellDialog对象的一个子对象*/
16     lineEdit->setValidator(new QRegExpValidator(regExp, this));
17     
18     connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
19     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
20 }
21 
22 /*启用或禁用OK按钮*/
23 void GoToCellDialog::on_lineEdit_textChanged()
24 {
25     /*QLineEdit::hasAcceptableInput()会使用在构造函数中设置的检验器来判断行编辑器中内容的有效性*/
26     okButton->setEnabled(lineEdit->hasAcceptableInput());
27 }

 

3. gotocelldialog.h

 1 /**/
 2 #ifndef GOTOCELLDIALOG_H
 3 #define GOTOCELLDIALOG_H
 4 
 5 #include <QDialog>
 6 
 7 #include "ui_gotocelldialog.h"
 8 
 9 class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
10 {
11     Q_OBJECT
12     
13 public:
14     GoToCellDialog(QWidget *parent = 0);
15     
16 private slots:
17     void on_lineEdit_textChanged();
18 };
19 
20 #endif

4. main.cpp

 1 #include <QApplication>
 2 
 3 #include "gotocelldialog.h"
 4 
 5 int main(int argc, char *argv[])
 6 {
 7     QApplication app(argc, argv);
 8     
 9     GoToCellDialog *dialog = new GoToCellDialog;
10     dialog->show();
11     
12     return app.exec();
13 }
14 
15 #if 0
16 
17 #include <QApplication>
18 #include <QDialog>
19 
20 #include "ui_gotocelldialog.h"
21 
22 
23 int main(int argc, char *argv[])
24 {
25     QApplication app(argc, argv);
26     
27     Ui::GoToCellDialog ui;
28     QDialog *dialog = new QDialog;
29     ui.setupUi(dialog);
30     dialog->show();
31     
32     return app.exec();
33 }
34 
35 #endif

 

转载于:https://www.cnblogs.com/seifguo/p/7076754.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值