I have a window which contains a QTreeView (databaseTreeView
) on a subclass of QAbstractTableModel (via a QSortFilterProxyModel).
I have an [Add] button which calls ui->databaseTreeView->model()->insertRow(ui->databaseTreeView->model()->rowCount());
.
I also have an [Edit] Button, which uses ui->databaseTreeView->selectionModel()->currentIndex();
to pass an index to an editor window.
I'd like to have the [Add] button automatically open an editor with the index of the newly created item, but as the model is sorted, I can't use the row number where I inserted the row. Plus insertRows()
only returns a bool (an index would be far more handy for my situation, so I'm wondering if anyone can tell me how to get the index of the newly added item).
I'm willing to devote two or three hours to it, refactoring if there's no alternative, but I would have thought it should be fairly simple. I'm looking inquisitively at the QAbstractItemModel::rowsInserted
signal, but that just returns the rows I gave insertRows()
, and edits the last item in the list, regardless of whether it was the item just added.
The full source can be found at https://github.com/megamasha/FlashKard for anyone to take a closer look.