更新时间:2023-12-03 21:09:10
只需使用以下命令将行计数设置为0:
Just set the row count to 0 with:
mTestTable->setRowCount(0);
它会通过调用 removeRows
来自动删除 QTableWidgetItem
,就像您在 QTableWidget
内部模型代码中看到的那样:
it will delete the QTableWidgetItem
s automatically, by calling removeRows
as you can see in QTableWidget
internal model code:
void QTableModel::setRowCount(int rows)
{
int rc = verticalHeaderItems.count();
if (rows < 0 || rc == rows)
return;
if (rc < rows)
insertRows(qMax(rc, 0), rows - rc);
else
removeRows(qMax(rows, 0), rc - rows);
}