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 = );
  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. int main(int argc, char *argv[])
  23. {
  24. QApplication app(argc, argv);
  25.  
  26. Ui::GoToCellDialog ui;
  27. QDialog *dialog = new QDialog;
  28. ui.setupUi(dialog);
  29. dialog->show();
  30.  
  31. return app.exec();
  32. }
  33.  
  34. #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. Django框架 之 跨域请求伪造

    Django框架 之 跨域请求伪造 浏览目录 同源策略与Jsonp 同源策略 Jsonp jQuery对JSONP的实现 CORS 简介 两种请求 同源策略与Jsonp 同源策略 同源策略(Same ...

  2. c++模板实现 linq

    // ConsoleApplication32.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" using namespace std; # ...

  3. mvc json 日期问题的最简单解决方法

    1.首先编写BaseController这个类,需要引入Newtonsoft.Json.dll程序集 using System;using System.Collections.Generic;usi ...

  4. html5操作类名API——classlist

    tagNode.classList.add('123'); // 添加类 tagNode.classList.remove('bbb'); // 删除类 tagNode.classList.toggl ...

  5. LightOJ 1282 Leading and Trailing (数学)

    题意:求 n^k 的前三位和后三位. 析:后三位,很简单就是快速幂,然后取模1000,注意要补0不全的话,对于前三位,先取10的对数,然后整数部分就是10000....,不用要,只要小数部分就好,然后 ...

  6. 【实习项目记录】(二) JSON

    介绍 JSON JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Program ...

  7. C# 类型初始化(Type initialization)

    这些天突然看到一些大虾门写的有关类型初始化的文章.那种感觉真叫跌宕起伏啊. 博文地址如下,自己慢慢体会吧! 起步:http://www.cnblogs.com/artech/archive/2008/ ...

  8. 《Andorid开源》greenDao 数据库orm框架

       一 前言:以前没用框架写Andorid的Sqlite的时候就是用SQLiteDatabase ,SQLiteOpenHelper ,SQL语句等一些东西,特别在写SQL语句来进行 数据库操作的时 ...

  9. 求整数数组(长度为n),出现大于2/n次数的数字

    条件:时间复杂度是O(n),空间复杂度是O(1) 方法1:标记法 , , , , , , , , , , , , , }; int len = arr.Length; int[] c = new in ...

  10. asp.netcore+jenkins+docker+svn+centos7.2 持续集成,每天凌晨获取最新代码打包发布

    运行环境: centos7.2服务器或则虚拟机 可以是腾讯云也可以是内网服务器,(如果是内网服务器需要用frp做内网穿透,这样才可以通过外网访问该服务器) svnserver 来托管代码 一.安装je ...