Disabling editing QLineEdit

Viewed 17638

I would like to make it so under certain conditions, it is impossible to edit a QLineEdit widget. Ideally, it would look something like:

QLE_On = QCheckBox("Non-editable?")
generic = QLineEdit()

if QLE_On.isChecked():
#disable editing of generic

Looking at the docs, .isReadOnly might be one possible option how to achieve what I'm looking for, but I'm not quite sure how to implement that.

3 Answers

Simply make the lineEdit uneditable by making it False:

self.lineEdit.setEnabled(False)

If you want the text to be selectable then use:

self.lineEdit.readOnly
Related