QTableWidget 清空除水平表头以外的其他单元格
void clearTableExceptHeaders() { int rowCount = tableWidget->rowCount(); int columnCount = tableWidget->columnCount(); // 清除所有单元格的内容 for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { QTableWidgetItem *item = tableWidget->item(row, col); if (item) { delete item; // 删除单元格中的项 } } } }