Esc key pressed on new row in edit mode deletes the row from view, but still triggers submit to database
-
Hi, I'm trying to use a QSqlTableModel whose edit strategy is set as OnRowChange. After creating a new row and start editing it in the view, I fill in the first record and press TAB to edit next record. At this point, if I press the ESC key the row disappears from the view, but somehow the engine still triggers the submit() slot in the model and the incomplete row is submitted to the database. I think that the row vanishing from the view is coherent with pressing an escape key, but in this case the model submit slot should not be called. Is there a way to fix this? Thanks!
-
Hi and welcome to devnet,
You should change to manual submit to handle your use case.
-
Thanks for the welcome and for the hint. In this case the easiest manual submit solution would be to place a 'submit' button for the user to click. I was thinking of a more 'automated' solution, but I guess I will have to place an event handler somewhere to detect navigation/enter/esc/row change events....Any hint on the best way to do that? Thanks
-
@SGaist I'll try doing that. The ESC capture must be done inside the editor used to enter new data, so I'll probably have to install the event filter in the delegate used to generate the editor. I'll see what I can do and post the results later.