//! 列数量
ui->tableWidget_FileList->setColumnCount(2);
//! 列标题
QStringList lstHead ={"文件名" , "大小" };
ui->tableWidget_FileList->setHorizontalHeaderLabels(lstHead);
//! 列宽自适应
ui->tableWidget_FileList->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
//! 单元格不可编辑
ui->tableWidget_FileList->setEditTriggers(QAbstractItemView::NoEditTriggers);
//! 整行选中
ui->tableWidget_FileList->setSelectionBehavior(QAbstractItemView::SelectRows);//! 仅单行选中
ui->tableWidget_FileList->setSelectionMode(QTableWidget::SingleSelection);//! 清空tableWidget
int rowCount = ui->tableWidget_FileList->rowCount();
for(int r = 0; r < rowCount; ++r)
{
ui->tableWidget_FileList->removeRow(0);
}//! 追加一行空行
int iRow = ui->tableWidget_FileList->rowCount();
ui->tableWidget_FileList->setRowCount(iRow + 1);
//! 填充数据
QTableWidgetItem *Name = new QTableWidgetItem(sFileName);
QTableWidgetItem *File = new QTableWidgetItem(sFileSize);
ui->tableWidget_FileList->setItem(iRow, 0, Name);
ui->tableWidget_FileList->setItem(iRow, 1, File);//! 获取选中行数据
QList
pItems = ui->tableWidget_FileList->selectedItems();
for(int i = 0; i < pItems.count(); i++)
{
int row = ui->tableWidget->row(pItems.at(i));
QTableWidgetItem *item = items.at(i);
QString text = item->text(); //获取内容
}