当前位置:网站首页>QDoubleValidator不生效问题解决办法
QDoubleValidator不生效问题解决办法
2022-07-27 08:58:00 【草丛中的蝈蝈】
问题:
使用QIntValidator正常,换为QDoubleValidator后不生效,看网上说的增加这行:setNotation(QDoubleValidator::StandardNotation);
好像也没什么作用,只好自己写了一个,目前测试感觉还行。
解决办法:
重载QDoubleValidator。
class MyDoublevalidator : public QDoubleValidator
{
Q_OBJECT
public:
MyDoublevalidator(QObject *parent = nullptr);
QValidator::State validate(QString &str, int &i) const;
};
MyDoublevalidator::MyDoublevalidator(QObject *parent)
{
}
QValidator::State MyDoublevalidator::validate(QString &str,int &i) const
{
qDebug() << "validate in: str" << str;
if(str == "-" || str == ""){
return Intermediate;
}
bool ok;
double number = str.toDouble(&ok);
if(!ok){
return Invalid;
}
// 判断小数点
int dotPos = str.indexOf('.');
if( (dotPos != -1) && (str.length()-dotPos - 1 > decimals()) ){
return Invalid;
}
// 区分负数还是正数
if(number >= 0)
{
if(number < bottom()){
return Intermediate;
}
if(number > top()){
return Invalid;
}
}
else
{
// 负数
if(number < bottom()){
return Invalid;
}
if(number > top()){
return Intermediate;
}
}
return Acceptable;
}
边栏推荐
- HUAWEI 机试题:火星文计算 js
- 【渗透测试工具分享】【dnslog服务器搭建指导】
- 苹果降价600元,对本就溃败的国产旗舰手机几乎是毁灭性打击
- 4278. Summit
- Activation functions commonly used in deep learning
- Deep understanding of Kalman filter (2): one dimensional Kalman filter
- 4275. Dijkstra序列
- [nonebot2] several simple robot modules (Yiyan + rainbow fart + 60s per day)
- Deep understanding of Kalman filter (3): multidimensional Kalman filter
- Tensorflow模型训练和评估的内置方法
猜你喜欢

Some practical, commonly used and increasingly efficient kubernetes aliases

BEVFormer: Learning Bird’s-Eye-View Representation from Multi-Camera Images via Spatiotemporal Trans

8 kinds of visual transformer finishing (Part 1)

【微服务~Sentinel】Sentinel之dashboard控制面板

【进程间通信IPC】- 信号量的学习

Deep understanding of Kalman filter (1): background knowledge

linux安装和远程连接mysql记录

CUDA programming-05: flows and events

PyQt5快速开发与实战 4.1 QMainWindow

Unity3D 2021软件安装包下载及安装教程
随机推荐
02 linear structure 3 reversing linked list
【进程间通信IPC】- 信号量的学习
HUAWEI 机试题:字符串变换最小字符串 js
Understand various IOU loss functions in target detection
A survey of robust lidar based 3D object detection methods for autonomous driving paper notes
691. Cube IV
Software testing function testing a full set of common interview questions [function testing - zero foundation] essential 4-1
Flink1.15源码阅读flink-clients客户端执行流程(阅读较枯燥)
Kibana uses JSON document data
3311. 最长算术
Test picture
MySQL Express
接口测试工具-Postman使用详解
ctfshow 终极考核
07_ Service registration and discovery summary
Matlab求解微分代数方程 (DAE)
Is it safe to buy funds every day? Online and other answers
Rewrite the tensorrt version deployment code of yolox
2036: [Blue Bridge Cup 2022 preliminary] statistical submatrix (two-dimensional prefix sum, one-dimensional prefix sum)
被三星和台积电挤压的Intel终放下身段,为中国芯片定制芯片工艺