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

2. gotocelldialog.cpp

 #include <QRegExp>

 #include "gotocelldialog.h"

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

3. gotocelldialog.h

 /**/
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H #include <QDialog> #include "ui_gotocelldialog.h" class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
{
Q_OBJECT public:
GoToCellDialog(QWidget *parent = ); private slots:
void on_lineEdit_textChanged();
}; #endif

4. main.cpp

 #include <QApplication>

 #include "gotocelldialog.h"

 int main(int argc, char *argv[])
{
QApplication app(argc, argv); GoToCellDialog *dialog = new GoToCellDialog;
dialog->show(); return app.exec();
} #if 0 #include <QApplication>
#include <QDialog> #include "ui_gotocelldialog.h" int main(int argc, char *argv[])
{
QApplication app(argc, argv); Ui::GoToCellDialog ui;
QDialog *dialog = new QDialog;
ui.setupUi(dialog);
dialog->show(); return app.exec();
} #endif

C++ GUI Qt4编程(05)-2.2GoToCell的更多相关文章

  1. C++ GUI Qt4编程(10)-3.4spreadsheet

    1. C++ GUI Qt4编程第三章,增加spreadsheet. 2. spreadsheet.h /**/ #ifndef SPREADSHEET_H #define SPREADSHEET_H ...

  2. C++ GUI Qt4编程(09)-3.3spreadsheet-toolbar

    1. C++ GUI Qt4编程第三章,增加工具栏.状态栏和快捷键. 2. mainwindow.h /**/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #i ...

  3. C++ GUI Qt4编程(08)-3.2spreadsheet-resource

    1. C++ GUI Qt4编程第三章,图片使用资源机制法. 2. 步骤: 2-1. 在resource文件夹下,新建images文件,存放图片. 2-2. 新建spreadsheet.qrc文件,并 ...

  4. C++ GUI Qt4编程(07)-3.1menu

    1. C++ GUI Qt4编程第三章,添加menu菜单. 2. mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include < ...

  5. C++ GUI Qt4编程(03)-1.3layout

    1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7:  Qt版本:5.5.13. 程序:layout.cpp #include <QApplication> #i ...

  6. C++ GUI Qt4编程(02)-1.2quit

    1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7:  Qt版本:5.5.13. 程序:quit.cpp #include <QApplication> #inc ...

  7. C++ GUI Qt4编程(01)-1.1Hello Qt

    1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7:  Qt版本:5.5.13. 程序:hello.cpp #include <QApplication> #in ...

  8. C++ GUI Qt4编程-创建自定义窗口部件

    C++ GUI Qt4编程-创建自定义窗口部件   Qtqt4 通过Qt窗口部件进行子类化或者直接对QWidget进行子类化,就可以创建自定义窗口部件,下面示范两种方式,并且也会说明如何把自定义窗口部 ...

  9. C++ GUI Qt4 编程 (第二版)

    [加拿大]JasminBlanchette [英]MarkSummerfield . 电子工业 2008. 前几天的问题多是因为版本不兼容的问题. QT本身Q4 Q5就有版本问题,然后集成到VS08 ...

随机推荐

  1. Entity Framework 6.0 Tutorials(1):Introduction

    以下系统文章为EF6.0知识的介绍,本章是第一篇 原文地址:http://www.entityframeworktutorial.net/entityframework6/introduction.a ...

  2. Mbatis——动态SQL

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "- ...

  3. Linq学习<三> linq to entity

    之前一直用sql选择出数据放在一个集合中,然后再用Linq或者lambda去操作数据,今天学了Linq to entity 才知道原来linq产生是为了Entity.也就是EDM(实体数据模型) 关于 ...

  4. vs2015 使用 Eazfuscator.NET 3.3

    出现问题: Unable to cast object System.Xml.XmlComment’ to type ‘System.Xml.XmlElement’ 解决办法: 打开 *.csproj ...

  5. Xamarin 笔记

    1. 报类 $(_DeviceSdkVersion) >= 21 异常,提示部署失败 解决办法:升级 xamarin for visual studio 2. 新建项目时,报“程序包安装错误”: ...

  6. 十六、Node.js-fs模块-流

    10. fs.createReadStream 从文件流中读取数据 /** * 之前我们学习过读取文件内容的方法readFile():该方法适合读取文件内容比较少的文件,如果遇到数据量庞大的文件,我们 ...

  7. 在didSelectRowAtIndexPath 里面取cell的方法

    1.选中了tableview的cell的某一行调用的代理方法 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(N ...

  8. javascript 数组排序

    var arr=[1,2,3,5,10,4,2,19,2,0]; alert(arr);//[1,2,3,5,10,4,2,19,2,0] arr.sort(function (a, b) {//升序 ...

  9. 设置使用的python版本

    一.查看当前使用的python版本,或设置使用的python版本 二.python2中默认使用ASCII码,无法识别中文,报错如图,解决办法,设置字符集为utf-8

  10. leecode刷题(5)-- 只出现一次的数字

    leecode刷题(5)-- 只出现一次的数字 只出现一次的数字 描述: 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明: 你的算法应该具 ...