from PyQt5.QtWidgets import *
import sys
class QlineEditMask(QWidget):掩码字符和组成分隔符:
def init(self):
super(QlineEditMask,self).init()
self.initUI()
def initUI(self):
self.setWindowTitle('用掩码限制Qline控件的输入')
formLayout = QFormLayout()
ipLineEdit = QLineEdit()
macLineEdit = QLineEdit()
dataLineEdit = QLineEdit()
licenLineEdit = QLineEdit()
ipLineEdit.setInputMask('000.000.000.000;_')
macLineEdit.setInputMask('HH:HH:HH:HH:HH:HH;_')
dataLineEdit.setInputMask('0000-00-00')
licenLineEdit.setInputMask('>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#')
formLayout.addRow("数字掩码",ipLineEdit)
formLayout.addRow("mac掩码",macLineEdit)
formLayout.addRow("日期掩码", dataLineEdit)
formLayout.addRow("许可证掩码", licenLineEdit)
self.setLayout(formLayout)
if name == ‘main’:
app = QApplication(sys.argv)
main = QlineEditMask()
main.show()
sys.exit(app.exec_())