PDA

View Full Version : QTableView, Sqlite db adds data although I press ESC key during table edit



tgrun
30th May 2021, 18:59
When I press the ADD button in my program I end up in the tableview edit mode and there I enter some text in the first two fields out of three but then I press ESC key which then puts me back in the tableview list and the new record seems to have been discarded which should be correct behavior. The problem is that the record is actually stored in the DB but I have to refresh the tableview to show it. Is there anyway I can catch this "ESC keypress" in the model setData method? Something like if (row edit is cancelled) then don't save it to DB else return QSqlTableModel::setData(index, value, role)? I´m very new to qt model/view programming but have some minor understanding of the concept.

ChrisW67
2nd June 2021, 09:52
We cannot any of how your program is constructed and what pressing the "ADD" button does.

You probably want to check QSqlTableModel::editStrategy(), but the default behaviour does not do what you are describing.