1

I have a QListView pulling data from a QSQLTableModel.

Upon a user clicking an 'Add' button, I add a new item and open it for editing:

QSqlTableModel *tblModel= qobject_cast<QSqlTableModel *>(ui->listView->model());
if(tblModel->insertRow(tblModel->rowCount()))
    ui->listView->edit(tblModel->index(tblModel->rowCount()-1, 1));

But once the user is done editing the new value, the selection of listView is lost. I can't find a signal on QListView or QSQLTableModel to handle when and edit has finished for me to 'restore' the selection.

Is there a way I can make sure the selection is kept?

Tim Jones
  • 307
  • 3
  • 11

1 Answers1

1

An excerpt from edit() function documentation:

Note that this function does not change the current index. Since the current index defines the next and previous items to edit, users may find that keyboard navigation does not work as expected. To provide consistent navigation behavior, call setCurrentIndex() before this function with the same model index.

Zeks
  • 2,265
  • 20
  • 32
  • Thanks, this does fix another niggling problem I had, but doesn't solve the problem I posted as once editing of the new item is finished (enter pressed or focus lost etc), the selection is reset. – Tim Jones Dec 08 '12 at 15:56