table->setSelectionMode(QAbstractItemView::SingleSelection)
table.horizontalHeader()->setResizeMode(QheaderView::Fixed);
table.horizontalHeader()->setStretchLastSection(true);
table.setEditTrigger(QAbstractItemView::NoEditTriggers);
table.setShowGrid(false);
//使行列头自适应宽度,最后一列将会填充空白部分
table->horizontalHeader()->setStretchLastSection(true);
//使行列头自适应宽度,所有列平均分来填充空白部分
table->horizontalHeader()->setResizeMode(QHeaderView::Strtch);
//使行自适应高度,假如行很多的话,行的高度不会一直减小,当达到一定值时会自动生成一个QScrollBar
table->verticalHeader()->setResizeMode(QHeaderView::Strtch);
//设置单击选择一行
table->setSelectionBehuavior(QAbstractItemView::SelectRows);
//设置每行内容不可编辑
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
//设置只能选择一行,不能选择多行
table->setSelectionMode(QAbstractItemView::SingleSelection);
/*去掉每行的行号*/
QHeaderView *headerView = table->verticalHeader();
headerView->setHidden(true);
/*设置让某个单元格或某行选中*/
选中单元格:table->setCurrentCell(row, column, QItemSelectionModel::Select);
选中一行:table->setCurrentCell(row, QItemSelectionModel::Select);(注意此处的列没有值)