QT中QTableWidget清空或删除内容功能

本文详细介绍了QT中QTableWidget的各种操作方法,包括如何清空整个表格、仅清除内容保留表头、删除特定单元格、行或列,以及移除标题头等。适用于需要在QT应用程序中灵活管理表格数据的开发者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天使用到了QT中QTableWidget的清空和删除功能,特地整理出。

参考https://blog.youkuaiyun.com/qq_16093323/article/details/79226349

如下:

1、void QTableWidget::clear() [slot]  

Removes all items in the view. This will also remove all selections and headers.

//清空表格中所有内容(包含表头)。

2、void QTableWidget::clearContents() [slot]

Removes all items not in the headers from the view. This will also remove all selections. The table dimensions stay the same.//清空表格中的内容(不包含表头)。

3、void QTableWidget::removeCellWidget(int row, int column) 

//删除表格中的某行中的某列内容。
 Removes the widget set on the cell indicated by row and column.

4、void QTableWidget::removeColumn(int column) [slot] 

//删除表格中的某列内容。
 Removes the column column and all its items from the table.

5、void QTableWidget::removeRow(int row) [slot]

 //删除表格中的某行内容。
 Removes the row row and all its items from the table

6、QTableWidgetItem * QTableWidget::takeItem(int row, int column) 

//删除表格中的某行和某列
 Removes the item at row and column from the table without deleting it.

7、QTableWidgetItem * QTableWidget::takeHorizontalHeaderItem(int column)

 //删除表格中的水平标题头
 Removes the horizontal header item at column from the header without deleting it.

8、QTableWidgetItem * QTableWidget::takeVerticalHeaderItem(int row) 

//删除表格中的垂直标题头
 Removes the vertical header item at row from the header without deleting it.

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值