qt 下tablewidget 中要单独使一列不能编辑怎么办
1个回答
展开全部
修改该列item的flags. 例如:
#include <QApplication>
#include <QTableWidget>
#include <QTableWidgetItem>
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();
}
#include <QApplication>
#include <QTableWidget>
#include <QTableWidgetItem>
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();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询