一、setInputMask()方法
setInputMask()方法用于设置QLineEdit中输入的掩码,语法为:
lineEdit.setInputMask(mask)
其中,mask为掩码。
演示:
from PyQt5.QtWidgets import QApplication, QLineEdit, QWidget, QVBoxLayout
app = QApplication([])
window = QWidget()
lineEdit = QLineEdit()
lineEdit.setInputMask("+99 99 9999 9999")
layout = QVBoxLayout()
layout.addWidget(lineEdit)
window.setLayout(layout)
window.show()
app.exec_()
运行后,QLineEdit中输入的内容会按照掩码的格式进行限制。
二、setText()方法
setText()方法用于设置QLineEdit中的文本内容,语法为:
lineEdit.setText(text)
其中,text为要设置的文本内容。
演示:
from PyQt5.QtWidgets import QApplication, QLineEdit, QWidget, QVBoxLayout
app = QApplication([])
window = QWidget()
lineEdit = QLineEdit()
lineEdit.setText("Hello World!")
layout = QVBoxLayout()
layout.addWidget(lineEdit)
window.setLayout(layout)
window.show()
app.exec_()
运行后,QLineEdit中的文本会被设置为“Hello World!”。
以上就是QLineEdit文本编辑的API大全介绍及演示。