修改该列item的flags. 例如:
#include
#include
#include
int main(int argc, char **argv)
{
QApplication app(argc, argv);
int col = 0;
QTableWidget *table = new QTableWidget(5, 3);
table->setItem(0, col, new QTableWidgetItem(QString("test")));
int i;
for(i = 0; i < table->rowCount(); i++){
QTableWidgetItem *item = table->item(i, col);
if(item) {
item->setFlags(item->flags() & (~Qt::ItemIsEditable));
} else {
item = new QTableWidgetItem;
item->setFlags(item->flags() & (~Qt::ItemIsEditable));
table->setItem(i, col, item);
}
}
table->show();
return app.exec();
}