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; // 删除单元格中的项
                }
            }
        }
    }

 

posted @ 2024-09-11 11:11  雾枫  阅读(32)  评论(0编辑  收藏  举报