I have a Qt project where I have a QStandardItemModel
called stockModel
. This model is linked to a QTableView
called tvStock
.
I have a button called btnDelete
which has a clicked
event set up as follows:
void StockItems::on_btnDelete_clicked()
{
//delete
}
How do I delete the selected row of tvStock
from stockModel
?
I assume I can start with this (but I'm not sure how to complete it):
stockModel->removeRow(/* What goes here? */);
Otherwise let me know if I'm completely on the wrong track.
Update:
I found and modified some code that allows to me to delete the row if the entire row's contents are selected:
QModelIndexList indexes = ui->tvStock->selectionModel()->selectedRows();
while (!indexes.isEmpty()) {
stockModel->removeRows(indexes.last().row(), 1);
indexes.removeLast();
}
Is there a way this code could be modified to delete the entire row if only one of the row items is selected?
Thanks!