I think I found a workaround.
In the setModelData I make sure that the length is greater then 3 before calling setData.
def setModelData(self, editor, model, index):
"""
Gets data from the editor widget and stores it in the specified model
at the item index.
The default implementation gets the value to be stored in the data model
from the editor widget's user property.
"""
# Call the setData method and set the data to the editors text. This
# allows the user to write the edit text back to the model.
if index.column() in [2, 3]:
# Only set the data if the len of the text is greater then 3.
# This means the data will not be set if it is less then 3.
# this will force the validator to be met here.
if len(editor.text()) >3:
model.
setData(index, QtCore.
QVariant(editor.
text()))
def setModelData(self, editor, model, index):
"""
Gets data from the editor widget and stores it in the specified model
at the item index.
The default implementation gets the value to be stored in the data model
from the editor widget's user property.
"""
# Call the setData method and set the data to the editors text. This
# allows the user to write the edit text back to the model.
if index.column() in [2, 3]:
# Only set the data if the len of the text is greater then 3.
# This means the data will not be set if it is less then 3.
# this will force the validator to be met here.
if len(editor.text()) >3:
model.setData(index, QtCore.QVariant(editor.text()))
To copy to clipboard, switch view to plain text mode
Bookmarks