删除Qtableview 选中行

/ /_tableModel是QStandardItemModel类,

QMessageBox::StandardButton reply = QMessageBox::question(NULL, "Delete", "Are you sure delete records?", QMessageBox::Yes | QMessageBox::No);
    if (reply == QMessageBox::No)
        return ;
 

    QItemSelectionModel *selections = ui.tableView->selectionModel();
    QModelIndexList selected = selections->selectedIndexes();
    QMap rowMap;
    foreach(QModelIndex index, selected)
    {        
        rowMap.insert(index.row(), 0);
    }
    int rowToDel;
    QMapIterator rowMapIterator(rowMap);
    rowMapIterator.toBack();
    while (rowMapIterator.hasPrevious())
    {
        rowMapIterator.previous();
        rowToDel = rowMapIterator.key();
        _tableModel->removeRow(rowToDel);
    }

对qtableview 一些基本操作:连接

https://blog.csdn.net/a724699769/article/details/54407812

你可能感兴趣的:(删除Qtableview 选中行)