PDA

View Full Version : QTableView, editing, validating input



jml
24th July 2007, 00:32
I'm using Qt4.2.3, and have created a custom model from QAbstractTableModel, using QTableView (for now). I want to be able to validate the input, and not let the user move to the next field if the input is invalid, and to give an error message in a text window. I set up an item delegate using QLineEdit as the editor, using a QValidator. The trouble is, this simply prevents the data from being stored in the model - the cursor still goes to the next field upon pressing TAB.

I found a post about using the QWidget::eventFilter function, and started writing code to handle the event of type LeaveEditFocus. But, the compiler (VS) says it is undefined! I can only guess it's because it's conditionally compiled conditioned on QT_KEYPAD_NAVIGATION being defined. Does anyone know why that wouldn't be defined. Is there a better solution to what I am trying to do?

Thanks for any help.

Jim L.
Seattle, WA

Michiel
24th July 2007, 00:57
There is a flags() function in your model. Reimplement that to turn off Qt::ItemIsEditable for those cells you don't want edited. I suppose that function could check if all previous cells have been validated or not.