Hi Everyone,
I have subclassed both a QSqlRelationalTableModel and a QtSql.QSqlRelationalDelegate. My question is with validation when editing a cell.
I have a createEditor method where I specify a line edit and add a regular expression validator to the lineEdit. The user can double click the cell and then click a different cell in the model and then the editor closes.
This allows the user to not enter anything into the cell and skip the validator. Is this normal behavior? How would I prevent the editor from closing until the regular expression is met?
Do I need to subclass the method commitAndCloseEditor to get this to work?
def createEditor(self, parent, option, index):
"""
This creates the editors and returns the widget used to edit the item
specified by index for editing.
The parent widget and style option are used to control how the
editor widget appears.
"""
if index.column() == EVENT_ALIAS:
regex
= QtCore.
QRegExp(r
"[a-zA-Z0-9_]{3,60}") lineEdit.setValidator(validator)
return lineEdit
# Else return the base method createEditor.
else:
return super(Delegate, self).createEditor(parent, option, index)
def createEditor(self, parent, option, index):
"""
This creates the editors and returns the widget used to edit the item
specified by index for editing.
The parent widget and style option are used to control how the
editor widget appears.
"""
if index.column() == EVENT_ALIAS:
lineEdit = QtGui.QLineEdit(parent)
regex = QtCore.QRegExp(r"[a-zA-Z0-9_]{3,60}")
validator = QtGui.QRegExpValidator(regex, parent)
lineEdit.setValidator(validator)
return lineEdit
# Else return the base method createEditor.
else:
return super(Delegate, self).createEditor(parent, option, index)
To copy to clipboard, switch view to plain text mode
Bookmarks