I'm looking for the way to limit line edit to accept only alphanumeric characters, dash and underscore (in whole line could be only one dash and one underscore), without spaces. I was looking at RegExp, but then I left this option, because I found some blog post which is explaining that RegExp is really slow. Now I don't know what is best way to limit line edit, so the output would be like I want.

What do you recommend me?

有帮助吗?

解决方案

You should read function QLineEdit::setValidator documentation and class QValidator documentation. You can define your own validator class (that inherits QValidator) and pass its object instance to QLineEdit object (using setValidator function).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top