请问,qt的QLineEdit如何设置,使他的默认输入法为数字

denggang0828 2010-05-14 11:24:07
请问,qt的QLineEdit如何设置,使他的默认输入法为数字
谢谢各位高手了。
...全文
2899 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
dbzhang800 2010-09-21
  • 打赏
  • 举报
回复
建议多看看Qt自带的manual

inputMethodHints : Qt::InputMethodHints
This property holds what input method specific hints the widget has.

This is only relevant for input widgets. It is used by the input method to retrieve hints as to how the input method should operate. For example, if the Qt::ImhFormattedNumbersOnly flag is set, the input method may change its visual components to reflect that only numbers can be entered.

Note: The flags are only hints, so the particular input method implementation is free to ignore them. If you want to be sure that a certain type of characters are entered, you should also set a QValidator on the widget.

The default value is Qt::ImhNone.

This property was introduced in Qt 4.6.

Access functions:

Qt::InputMethodHints inputMethodHints () const
void setInputMethodHints ( Qt::InputMethodHints hints )
Kevin_Beyond_Shi 2010-09-21
  • 打赏
  • 举报
回复
看来楼上的都误解楼主的意思了。

用inputMode,不过只能设置text、number和doubble三种方式。
qter_wd007 2010-05-15
  • 打赏
  • 举报
回复
setInputMask()

具体可以查阅帮助中的说明。
denggang0828 2010-05-15
  • 打赏
  • 举报
回复
是这样的 我是在5800上做的东西 是触屏的 要输入东西的话得先点击QLineEdit这个空间进入输入界面 默认的是输入字符什么的 我想让他默认的是数字
gemfield 2010-05-14
  • 打赏
  • 举报
回复
或者inputMask ()
gemfield 2010-05-14
  • 打赏
  • 举报
回复
默认输入法?
用regular expressions正则表达式吧
tingsking18 2010-05-14
  • 打赏
  • 举报
回复
数字输入法 是什么?
denggang0828 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 tingsking18 的回复:]

QValidator *validator = new QIntValidator(this);
ui->lineEdit->setValidator(validator);
[/Quote]

这种方法是有用 只能输入数字 但是我输入的时候还是得从字符输入法切一下到数字输入法
我的意思是将默认的输入法改成数字输入法
这个能实现吗?
tingsking18 2010-05-14
  • 打赏
  • 举报
回复
QValidator *validator = new QIntValidator(this);
ui->lineEdit->setValidator(validator);
denggang0828 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 tingsking18 的回复:]

QRegExp regExp("^[-]?\d+[.]?\d*$");
m_ScanHeight->setValidator(new QRegExpValidator(regExp,this));
帮助上有
[/Quote]


我刚刚试过了
可是还是不行
QLineEdit点进去之后 默认的输入方式还是输入字母的 请问这是怎么回事啊?
tingsking18 2010-05-14
  • 打赏
  • 举报
回复
QRegExp regExp("^[-]?\d+[.]?\d*$");
m_ScanHeight->setValidator(new QRegExpValidator(regExp,this));
帮助上有
denggang0828 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tingsking18 的回复:]

正则表达式
^[-]?\d+[.]?\d*$
[/Quote]


这个具体怎么用呢? 看不懂啊
请高人赐教
tingsking18 2010-05-14
  • 打赏
  • 举报
回复
正则表达式
^[-]?\d+[.]?\d*$
denggang0828 2010-05-14
  • 打赏
  • 举报
回复
就是一般的输入法默认的为输入字母,我想让他默认就是输入数字,不用再去切换输入法
inputMask ()具体怎么实现呢? 麻烦您能不能详细的说下啊,谢啦
万分感激

16,215

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧