当前位置:编程学习 > wap >>

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

请问,qt的QLineEdit如何设置,使他的默认输入法为数字
谢谢各位高手了。 --------------------编程问答-------------------- 默认输入法?
用regular expressions正则表达式吧 --------------------编程问答-------------------- 或者inputMask () --------------------编程问答-------------------- 就是一般的输入法默认的为输入字母,我想让他默认就是输入数字,不用再去切换输入法
inputMask ()具体怎么实现呢? 麻烦您能不能详细的说下啊,谢啦
万分感激 --------------------编程问答-------------------- 正则表达式
^[-]?\d+[.]?\d*$ --------------------编程问答--------------------
引用 4 楼 tingsking18 的回复:
正则表达式
^[-]?\d+[.]?\d*$



这个具体怎么用呢? 看不懂啊
请高人赐教 --------------------编程问答-------------------- QRegExp regExp("^[-]?\d+[.]?\d*$");
m_ScanHeight->setValidator(new QRegExpValidator(regExp,this));
帮助上有 --------------------编程问答--------------------
引用 6 楼 tingsking18 的回复:
QRegExp regExp("^[-]?\d+[.]?\d*$");
m_ScanHeight->setValidator(new QRegExpValidator(regExp,this));
帮助上有



我刚刚试过了
可是还是不行
QLineEdit点进去之后  默认的输入方式还是输入字母的  请问这是怎么回事啊? --------------------编程问答--------------------     QValidator *validator = new QIntValidator(this);
    ui->lineEdit->setValidator(validator); --------------------编程问答--------------------
引用 8 楼 tingsking18 的回复:
    QValidator *validator = new QIntValidator(this);
    ui->lineEdit->setValidator(validator);


这种方法是有用 只能输入数字 但是我输入的时候还是得从字符输入法切一下到数字输入法
我的意思是将默认的输入法改成数字输入法
这个能实现吗? --------------------编程问答-------------------- 数字输入法  是什么? --------------------编程问答-------------------- 是这样的  我是在5800上做的东西 是触屏的  要输入东西的话得先点击QLineEdit这个空间进入输入界面   默认的是输入字符什么的 我想让他默认的是数字 --------------------编程问答-------------------- setInputMask()

具体可以查阅帮助中的说明。 --------------------编程问答-------------------- 看来楼上的都误解楼主的意思了。

用inputMode,不过只能设置text、number和doubble三种方式。 --------------------编程问答-------------------- 建议多看看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 )
补充:移动开发 ,  Qt
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,