QTableWidget清空或刪除內容及表頭樣式內容
阿新 • • 發佈:2018-12-02
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、取消表頭的在選中單元格時的高亮狀態 ui->tableWidget->verticalHeader()->setHighlightSections(false);//取消表頭的在選中單元格時的高亮狀態。 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自帶行號列