Donnerstag, 28. Oktober 2010

QDataWidgetMapper annoyances

QDataWidgetMapper looks like a nice class to edit database records in a custom dialog. However I found it to have some rather annoying side effects:
  • it eats the Esc key (by reverting the editor values) so you cannot close the dialog with Esc any longer
  • If the submit policy is AutoSubmit, the cursor in any QLineEdit that is connected to the mapper will not keep its position when switching to another application and back.
Issue #1 can be solved with an eventFilter.
Issue #2 can be solved by using ManualSubmit and something like this:

connect(ui->saveButton, SIGNAL(clicked()), m_mapper, SLOT(submit()));
connect(this, SIGNAL(accepted()), m_mapper, SLOT(submit()));