1. hexspinbox.cpp

 /*
* The spin box supports integer values but can be extended to use different strings
* with validate(), textFromValue() and valueFromText().
*/
#include "hexspinbox.h" #include <QRegExpValidator> HexSpinBox::HexSpinBox(QWidget *parent)
: QSpinBox(parent)
{
setRange(, ); /*设置默认范围是从0到255*/
validator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,8}"), this);
} QValidator::State HexSpinBox::validate(QString &text, int &pos) const
{
return validator->validate(text, pos);
} QString HexSpinBox::textFromValue(int value) const
{
return QString::number(value, ).toUpper();
} int HexSpinBox::valueFromText(const QString &text) const
{
bool ok;
return text.toInt(&ok, );
}

2. hexspinbox.h

 #ifndef HEXSPINBOX_H
#define HEXSPINBOX_H #include <QSpinBox> class QRegExpValidator; class HexSpinBox : public QSpinBox
{
Q_OBJECT public:
HexSpinBox(QWidget *parent = ); protected:
QValidator::State validate(QString &text, int &pos) const;
QString textFromValue(int value) const;
int valueFromText(const QString &text) const; private:
QRegExpValidator *validator;
}; #endif /*HEXSPINBOX_H*/

3. main.cpp

 #include <QApplication>

 #include "hexspinbox.h"

 int main(int argc, char *argv[])
{
QApplication app(argc, argv); HexSpinBox *hexSpinBox = new HexSpinBox;
hexSpinBox->show(); return app.exec();
}

4. 效果

C++ GUI Qt4编程(11)-5.1hexSpinbox的更多相关文章

  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. Luogu 4755 Beautiful Pair

    分治 + 主席树. 设$solve(l, r)$表示当前处理到$[l, r]$区间的情况,我们可以找到$[l, r]$中最大的一个数的位置$mid$,然后扫一半区间计算一下这个区间的答案. 注意,这时 ...

  2. laravel与front-end

    准备工作 在此之前要安装node  . npm .这里安装node . npm 就不介绍了,百度一大把. 安装所有的npm依赖包 //进入项目的根目录 npm install 安装完后会出现一个nod ...

  3. 使用jQuery完成表单验证

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>注 ...

  4. (转)Asp.Net生命周期系列五

    原文地址:http://www.cnblogs.com/skm-blog/p/3188697.html 如果您看了我的前四篇文章,应该知道目前Http请求已经流到了HttpModule这个程序员手中了 ...

  5. 编写高质量代码改善C#程序的157个建议——建议26:使用匿名类型存储LINQ查询结果

    建议26:使用匿名类型存储LINQ查询结果 从.NET3.0开始,C#开始支持一个新特性:匿名类型.匿名类型有var.赋值运算符和一个非空初始值(或以new开头的初始化项)组成.匿名类型有如下基本特性 ...

  6. 20169219 SEED SQL注入实验

    实验环境SEED Ubuntu镜像 环境配置 实验需要三样东西,Firefox.apache.phpBB2(镜像中已有): 1.运行Apache Server:只需运行命令sudo service a ...

  7. LeftStr函数使用

    LeftStr(s, i); 表示返回字符串s的左边共I位字符的一个新字符串. var i: integer; s: string; result: string; begin i := ; s := ...

  8. oracle 中 创建序列sequence

    drop sequence SEQ_YCXWP_CGD; create sequence SEQ_YCXWP_CGD increment start nomaxvalue;

  9. 匿名函数和lamda表达式

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. Office Diary(工作日记本)

    Office Diary 是一款免费.绿色小巧的写日记和收集文档资料的软件,界面效仿Office Word ,支持Word中常用的文字编辑排版功能,可以作为Microsoft Office产品系列的强 ...