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. 验证码测试-demo

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

  2. 基本滤波算法比较 (转载http://blog.sina.com.cn/s/blog_69f2aa5a01014du5.html)

    最近在做关于数据采集方面的东西,这就不免涉及到了滤波的算法,在网上找到了关于几种算法的比较. 数字滤波方法有很多种,每种方法有其不同的特点和使用范围.从大的范围可分为3类. 1.克服大脉冲干扰的数字滤 ...

  3. Java 数据结构之数组

    public class Arrays {    //创建一个Integer空数组    public static Integer[] player=null;    //添加球员号码    pri ...

  4. POJ2442 Sequence(堆的骚操作)

    Description Given m sequences, each contains n non-negative integer. Now we may select one number fr ...

  5. C#Thread学习

    一.Thread的使用方式 1.不带参数 (1)使用lambda public static void fun1() { Console.WriteLine($"Main ThreadId: ...

  6. WebStrom-JS编程小技巧

    快速打印某个名为***的对象:***.log回车效果如下:

  7. 洛谷P2510 [HAOI2008]下落的圆盘(计算几何)

    题面 传送门 题解 对于每个圆,我们单独计算它被覆盖的周长是多少 只有相交的情况需要考虑,我们需要知道相交的那段圆弧的角度,发现其中一个交点和两个圆的圆心可以构成一个三角形且三边都已经知道了,那么我们 ...

  8. centos6.3安装 jdk-8u131-linux-x64.gz

    解压指令为:tar -zxvf jdk-8u131-linux-x64.gz 设置环境变量,首先是打开设置环境变量的文件夹,指令为:vi /etc/profile     然后在英文输入法下切换到“插 ...

  9. 更改Linux下的时间

    1.使用tzseletect glibc-common-2.12-1.192.el6.x86_64 : Common binaries and locale data for glibc Repo : ...

  10. Sample-Code:Translator

    <h2>My Spanish Translator</h2> <p> Enter your text in English:  </p> <p&g ...