我QRegExpValidator一直认为我的输入是Acceptable- 它不应该是。在 gui.py 中有一个QLineEdit名为`
from gui import Ui_Dialog
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5 import QtCore
from PyQt5.QtGui import QRegExpValidator
from PyQt5.QtCore import QRegExp
import sys
class AppWindow(QDialog):
def __init__(self):
super().__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.show()
self.ui.number.textChanged[str].connect(self.validate_number)
def validate_number(self):
regex = QRegExp("^[0-9]{3}$")
tmp = QRegExpValidator(regex, self.ui.number)
print(tmp.Acceptable)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = AppWindow()
w.show()
sys.exit(app.exec_())
2
无论我尝试什么,输出总是如此。我希望我输入任何内容,如果它是 3 位数字,则该函数返回 True(或可接受)。
波斯汪
相关分类