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 ...
随机推荐
- ShopNc登录验证码
- 数据库连接池DBUtils
安装 pip3 install DBUtils DBUtils是Python的一个用于实现数据库连接池的模块. 此连接池有两种连接模式: 模式一:为每个线程创建一个连接,线程即使调用了close方法, ...
- Oracle 已连接到空闲例程或ORA-01034: ORACLE not available
因为是本地数据库没有重要资料,所以可以随便自己折腾. 出现问题原因:从生产数据库导入一个表到本地库测试,因数据量过大,在导入4-5个小时后,手动中断导入.是否异常关机不能确定. 之后再打开数据库出现一 ...
- Android ActionBar仿微信界面
ActionBar仿微信界面 1.学习了别人的两篇关于ActionBar博客,在结合别人的文章来仿造一下微信的界面: 思路如下:1).利用ActionBar生成界面的头部,在用ActionBar的Ac ...
- SurfaceView和SurfaceHolder的基本用法
仅做记录使用,新手也可以来看看,怎么得到一个surfaceholder. 1.在xml文件中增加一个surfaceView控件. <SurfaceView android:layout_widt ...
- WinForm中DataGridView的使用(三) - 各种事件
CellMouseDown/CellMouseUp 可获得行.列号 可用if (rowIndex >= 0 && e.Y > 4 && e.Y < ( ...
- 同一个程序里有多个版本的App
在Xcode中添加多个targets进行版本控制,就是同一个app开发多个版本 以Xcode 9.3 为例 1. 创建 点击左侧工程项目文件,选择TARGETS 下的项目右击选择 Duplicate. ...
- NSSet集合
前言 NSSet:集合 NSSet 集合跟数组差不多,但 Set 集合不能存放相同的对象,它是一组单值对象的集合,被存放进集合中的数据是无序的,它可以是可变的,也可以是不变的. Xcode 7 对系统 ...
- [SinGuLaRiTy] 树链问题
[SinGuLaRiTy-1035] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 关于树链 树链是什么?这个乍一看似乎很陌生的词汇表达的其 ...
- 【bzoj4514】: [Sdoi2016]数字配对 图论-费用流
[bzoj4514]: [Sdoi2016]数字配对 好像正常的做法是建二分图? 我的是拆点然后 S->i cap=b[i] cost=0 i'->T cap=b[i] cost=0 然后 ...