Qt QLineEdit 输入框设置经纬度

因项目需要,将输入框的输入格式设置为经纬度的格式,如经度E123°23'45"和纬度N31°54'29",需要考虑数据的有效性,防止非法数据的输入。

主要用 setValidator 检验数据的有效性(用正则表达式),用 setInputMask 限制输入的格式,直接上代码:

// 经度
QLineEdit *lineEdit_Longitude = new QLineEdit(this);
lineEdit_Longitude->setGeometry(100, 100, 180, 80);
QRegExp regExp_Longitude("(E|W)?[0-1][0-7]\\d°[0-5]\\d'[0-5]\\d\"");
lineEdit_Longitude->setValidator(new  QRegExpValidator(regExp_Longitude, lineEdit_Longitude));
lineEdit_Longitude->setInputMask("A000°00'00\"");
lineEdit_Longitude->setText("E000°00'00\"");

// 纬度
QLineEdit *lineEdit_Latitude = new QLineEdit(this);
lineEdit_Latitude->setGeometry(100, 200, 180, 80);
QRegExp regExp_Latitude("(N|S)?[0-8]\\d°[0-5]\\d'[0-5]\\d\"");
lineEdit_Latitude->setValidator(new  QRegExpValidator(regExp_Latitude, lineEdit_Latitude));
lineEdit_Latitude->setInputMask("A00°00'00\"");
lineEdit_Latitude->setText("N00°00'00\"");

  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在于GIS相关的软件中经常要输入经纬度数值,而基于MFC Edit控件经纬度输入控件需 要创建三个Edit编辑框,来分别输入度、分、秒数值,并且需要分别进行输入范围和有效 性的检验。该基于BCGControlBar的经纬度输入控件实现了在一个输入窗口中分别按照度 、分、秒三个值域来输入经纬度数值,并同时进行了输入分有效性和输入范围的检验。经 纬度中的度、分、秒字段均通过数字键盘直接输入数值,也可通过微调按钮或者键盘的上 下键进行数字的增减,你可以通过左右键进行度、分、秒输入域的切换。该控件可以设置 度的输入范围,默认的度范围是0~89。该1.1版本修复了键盘直接输入数值的逻辑问题。 In the GIS-related software often have to enter the latitude and longitude values, and MFC Edit control based on the latitude and longitude input controls need to create three Edit edit box to enter the degrees, minutes and seconds values, and the need for input range and validity of the test. The BCGControlBar-based latitude and longitude input control realizes the input of the latitude and longitude values in degrees,minutes,and seconds in one input window, and simultaneously verifies the validity of the input points and the input range.The degrees, minutes, and seconds fields can be entered directly through the numeric keypad, also can be fine-tuning button or the keyboard up and down keys to increase or decrease the number, you can use left and right keys for degrees, minutes and seconds to switch the input field. The control can set the input range of degree, the default range is 0 ~ 89.The 1.1 version fixes the logic of keyboard input values directly.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值