【发布时间】:2018-12-20 17:49:15
【问题描述】:
将 setInputMask 和 setValidator IPv4 地址组合到 QlineEdit 中的问题
我有一个 QLineEdit 来设置我的 IPv4 地址。 第一次,我用 setInputMask 将我的 QLineEdit 设置为“......” 第二次,我使用 Ip Validator 来检查它是否是 IP 地址
问题是当我单独使用时,它可以工作,但一起使用时,我无法编辑我的 QLineEdit...
self.lineEdit_IP = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_IP.setGeometry(120,0,160,30)
self.lineEdit_IP.setStyleSheet("background-color: rgb(255, 255, 255);")
self.lineEdit_IP.setAlignment(QtCore.Qt.AlignHCenter)
self.lineEdit_IP.setInputMask("000.000.000.000")
#Set IP Validator
regexp = QtCore.QRegExp('^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){0,3}$')
validator = QtGui.QRegExpValidator(regexp)
self.lineEdit_IP.setValidator(validator)
【问题讨论】:
-
尝试将
self.lineEdit_IP.setInputMask ("000.000.000.000")更改为self.lineEdit_IP.setInputMask ("000.000.000.000;0")
标签: python pyqt pyqt5 qlineedit