如何使 QTableWidget 中的列只读? [英] How to make a column in QTableWidget read only?

查看:66
本文介绍了如何使 QTableWidget 中的列只读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在 QTableWidget 中有一列 不可 可编辑.
在论坛中,我已经阅读了很多关于一些 flags 的内容,但无法实现.

I would like to have one column in QTableWidget NOT editable.
In forums I have read a lot about some flags but could not manage to implement.

推荐答案

在 QTableWidget 中插入以下类型的项目:

Insert into the QTableWidget following kind of items:

QTableWidgetItem *item = new QTableWidgetItem();
item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);

工作正常!

QTableWidgetItem *item = new QTableWidgetItem();
item->setFlags(item->flags() ^ Qt::ItemIsEditable);

这是一个更好的解决方案.感谢@priomsrb.

This is a better solution. Thanks to @priomsrb.

这篇关于如何使 QTableWidget 中的列只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆