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?

Qt Code:
  1. def createEditor(self, parent, option, index):
  2. """
  3. This creates the editors and returns the widget used to edit the item
  4. specified by index for editing.
  5.  
  6. The parent widget and style option are used to control how the
  7. editor widget appears.
  8. """
  9.  
  10. if index.column() == EVENT_ALIAS:
  11. lineEdit = QtGui.QLineEdit(parent)
  12. regex = QtCore.QRegExp(r"[a-zA-Z0-9_]{3,60}")
  13. validator = QtGui.QRegExpValidator(regex, parent)
  14. lineEdit.setValidator(validator)
  15. return lineEdit
  16.  
  17. # Else return the base method createEditor.
  18. else:
  19. return super(Delegate, self).createEditor(parent, option, index)
To copy to clipboard, switch view to plain text mode