如何在pyqt中限制QLineEdit中的用户输入 [英] How to restrict user input in QLineEdit in pyqt
本文介绍了如何在pyqt中限制QLineEdit中的用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 QLineEdit
,我想限制 QLineEdit
只接受整数.它应该像输入掩码一样工作.但我不想使用 inputmask
,因为如果用户点击 QLineEdit
光标将在鼠标点击的位置.并且用户需要导航到 0 位置并输入他想要的前夕.
I have a QLineEdit
and i want to restrict QLineEdit
to accept only integers. It should work like inputmask. But I dont want to use inputmask
, because if user clicks on QLineEdit
cursor will be at the position where mouse was clicked. and user need to navigate to 0 position and type what eve he wants.
有没有其他替代方法.
推荐答案
你可以使用 QValidator 它的工作原理是:
you can use QValidator it works like:
#To allow only int
self.onlyInt = QIntValidator()
self.LineEdit.setValidator(self.onlyInt)
这篇关于如何在pyqt中限制QLineEdit中的用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文