1

Как сделать так, что бы можно было вводить только буквы в lineEdit?

1 ответ 1

1

void QLineEdit::setValidator(const QValidator *v)

Устанавливает валидатор для значений редактирования строки на v.

Больше https://doc.qt.io/qt-5/qlineedit.html#setValidator

from PyQt5 import QtGui, QtWidgets, QtCore

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.lineEdit= QtWidgets.QLineEdit()
        
        rx  = QtCore.QRegExp("[a-zA-Zа-яА-Я .,]{100}")    
        val = QtGui.QRegExpValidator(rx)                 
        self.lineEdit.setValidator(val)                   
        self.setCentralWidget(self.lineEdit)

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())

введите сюда описание изображения

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.