• 8971阅读
  • 5回复

[提问]怎么在qtablewidget中用validator? [复制链接]

上一主题 下一主题
离线colourwoo
 

只看楼主 倒序阅读 楼主  发表于: 2013-03-11
一个表格,限制某列的输入内容必须为浮点型。

qlineEdit有setValidator()
那qtablewidget类似的功能怎么实现?

谢谢!

离线退避九舍

只看该作者 1楼 发表于: 2013-03-11
正则表达式?
离线colourwoo

只看该作者 2楼 发表于: 2013-03-11
What you can do is just create a QDoubleValidator...retrieve the string from the QTableWidgetItem...and call the validate method of your QDoubleValidator passing it the value of your QTableWidgetItem. It will return a QValidator::State that you can check to make sure it is valid.

度娘真是渣。
某歌第一条。

我试试这个办法。回头报告
离线pxiao_xiao

只看该作者 3楼 发表于: 2013-03-12
引用第2楼colourwoo于2013-03-11 16:09发表的  :
What you can do is just create a QDoubleValidator...retrieve the string from the QTableWidgetItem...and call the validate method of your QDoubleValidator passing it the value of your QTableWidgetItem. It will return a QValidator::State that you can check to make sure it is valid.
度娘真是渣。
某歌第一条。
.......

受教了
离线wangyan23888

只看该作者 4楼 发表于: 2013-12-13
回 2楼(colourwoo) 的帖子
这个限制输入数字 可行吗?谢谢
离线jackiceye

只看该作者 5楼 发表于: 2013-12-19
这样就可以显示整型数字:
qlineEdit->setValidator(new QIntValidator(1, 65535, this));
快速回复
限100 字节
 
上一个 下一个