QTableWidget清空或删除内容及表头样式内容

您所在的位置:网站首页 税务登记变更事项是什么 QTableWidget清空或删除内容及表头样式内容

QTableWidget清空或删除内容及表头样式内容

2023-11-20 04:49| 来源: 网络整理| 查看: 265

今天使用到了QTableWidget的清空和删除,特地整理出。如下:

目录

1、清空表格中所有内容

 2、清空表格中的内容(不包含表头)

3、删除表格中的某行中的某列内容

4、删除表格中的某列内容

5、删除表格中的某行内容

6、删除表格中的某行和某列

7、删除表格中的水平标题头

8、删除表格中的垂直标题头

9、设置该单元格为屏蔽状态,不能编辑和选中

10、取消表头的在选中单元格时的高亮状态

 11、QTableWidget设置为整行选中

12、设置表头的样式

13、删除QTableWidget自带的行号

14、设置QTableWidget内容居中

15、QTableWidget设置最后一列自动填充表格

16、QTableWidget隐藏序号列

17、QTableWidget设置最后一列自动填充表格

18、QTableWidget设置水平表头

19、在使用QTableWidget显示图片、文字等信息

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. 9、设置该单元格为屏蔽状态,不能编辑和选中 ui->tableWidget->item(0,0)->setFlags(Qt::ItemIsEditable);//设置该单元格为屏蔽状态,不能编辑和选中。  10、取消表头的在选中单元格时的高亮状态 ui->tableWidget->horizontalHeader()->setHighlightSections(false);//取消表头的在选中单元格时的高亮状态。  11、QTableWidget设置为整行选中 ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); 12、设置表头的样式 ui->tableWidget->horizontalHeader()->setStyleSheet(“image: url(:/img/a.png);image-position:left; “); //设置表头的样式。  13、删除QTableWidget自带的行号 QHeaderView* headerView = ui->tableWidget->verticalHeader();//m_ItemTable为QTableWidget headerView->setHidden(true);//隐藏tablewidget自带行号列 14、设置QTableWidget内容居中 QTableWidgetItem *item; item = new QTableWidgetItem; item->setText(userInfo.userId); item->setTextAlignment(Qt::AlignCenter);//设置内容对齐方式为垂直和水平居中 ui->tableWidget->setItem(i, 0, item); 15、QTableWidget设置最后一列自动填充表格 ui->tableWidget->horizontalHeader()->setStretchLastSection(true); 16、QTableWidget隐藏序号列 QHeaderView* headerView = m_ItemTable->verticalHeader();//隐藏序号列 headerView->setHidden(true); 17、QTableWidget设置最后一列自动填充表格 ui->tableWidget->horizontalHeader()->setStretchLastSection(true); //设置最后一列自动填充表格 ui->tableWidget->horizontalHeader()->setResizeContentsPrecision(QHeaderView::Stretch); 18、QTableWidget设置水平表头 QStringList header; header


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3