C++ GUI Qt4编程(11)-5.1hexSpinbox
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的更多相关文章
- C++ GUI Qt4编程(10)-3.4spreadsheet
1. C++ GUI Qt4编程第三章,增加spreadsheet. 2. spreadsheet.h /**/ #ifndef SPREADSHEET_H #define SPREADSHEET_H ...
- C++ GUI Qt4编程(09)-3.3spreadsheet-toolbar
1. C++ GUI Qt4编程第三章,增加工具栏.状态栏和快捷键. 2. mainwindow.h /**/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #i ...
- C++ GUI Qt4编程(08)-3.2spreadsheet-resource
1. C++ GUI Qt4编程第三章,图片使用资源机制法. 2. 步骤: 2-1. 在resource文件夹下,新建images文件,存放图片. 2-2. 新建spreadsheet.qrc文件,并 ...
- C++ GUI Qt4编程(07)-3.1menu
1. C++ GUI Qt4编程第三章,添加menu菜单. 2. mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include < ...
- C++ GUI Qt4编程(03)-1.3layout
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:layout.cpp #include <QApplication> #i ...
- C++ GUI Qt4编程(02)-1.2quit
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:quit.cpp #include <QApplication> #inc ...
- C++ GUI Qt4编程(01)-1.1Hello Qt
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:hello.cpp #include <QApplication> #in ...
- C++ GUI Qt4编程-创建自定义窗口部件
C++ GUI Qt4编程-创建自定义窗口部件 Qtqt4 通过Qt窗口部件进行子类化或者直接对QWidget进行子类化,就可以创建自定义窗口部件,下面示范两种方式,并且也会说明如何把自定义窗口部 ...
- C++ GUI Qt4 编程 (第二版)
[加拿大]JasminBlanchette [英]MarkSummerfield . 电子工业 2008. 前几天的问题多是因为版本不兼容的问题. QT本身Q4 Q5就有版本问题,然后集成到VS08 ...
随机推荐
- 500 Internal Server Error
解决策略: 1.httpd.conf中,开启apache头信息自定义模块 2.htaccess文件,对这个域名的资源进行访问时,添加一个头信息 Header set Access-Control-Al ...
- c# 导入c++ dll
1.类的函数的内联实现 #include "stdafx.h" #include "testdll.h" #include <iostream> # ...
- Entity Framework 6.0 Tutorials(10):Index Attribute
Index Attribute: Entity Framework 6 provides Index attribute to create Index on a particular column ...
- rest-framework之序列化组件
一:django自带序列化组件 Django内置的serializers(把对象序列化成json字符串) from django.core import serializers def test(re ...
- How to Choose the Best Way to Pass Multiple Models in ASP.NET MVC
Snesh Prajapati, 8 Dec 2014 http://www.codeproject.com/Articles/717941/How-to-Choose-the-Best-Way-to ...
- 【Head First Java 读书笔记】(二)类与对象
前篇当中,代码都放在main()里面,那根本不是面向对象的做法. 椅子大战(对象如何改变你的一生) 程序规格: 在图形接口画出四方形,圆形和三角形,当用户点选图形时,图形需要顺时针转360度并依据形状 ...
- Spring源码研究:数据绑定
在做Spring MVC时,我们只需用@Controllor来标记Controllor的bean,再用@RequestMapping("标记")来标记需要接受请求的方法,方法中第一 ...
- Daily translation 3th
Source url:http://www.nzherald.co.nz/education/news/article.cfm?c_id=35&objectid=11149719 //plac ...
- java设计模式 策略
什么是策略设计模式? 世界永远都在变,唯一不变的就是变本身 举个生活中的例子,小时候玩的游戏中,Sony的PSP提供了统一的卡槽接口,玩家只要更换卡带就可以达到更换游戏的目的,做到了一机多用 特工执行 ...
- Duration Assertion(持续时间)
Duration Assertion用来测试每一个响应的时间是否小于给定的值,任何超过给定毫秒数的响应都会标记为失败. Duration in milliseconds:响应的持续时间是否在给定的值范 ...