storm_to storm_to - 1 month ago 12
Python Question

pyqt4 QComboBox setEditable(True) - How to setMaxLength?

I have a QComboBox that is tied to database VARCHAR(45) field.

The QComboBox dropdown list provides a set of default values but it is EDIT enabled and user can enter anything in it.

I want to limit the user entry length to max of 45 chars

QComboBox does not have a setMaxLength(int) like QLineEdit does.

Anyone have any suggestions?

self.myDropDown = QComboBox()
self.myDropDown.setEditable(True)


Thanks

Answer

If a combo-box is editable, its lineEdit method will give access to its line-edit widget:

self.myDropDown = QComboBox()
self.myDropDown.setEditable(True)
self.myDropDown.lineEdit().setMaxLength(45)
Comments