找回密码
 立即注册
收起左侧

QTableView 如何让某列不可编辑啊? 配合QStandardItemModel

4
回复
11582
查看
[复制链接]
累计签到:70 天
连续签到:1 天
来源: 2016-1-27 17:17:36 显示全部楼层 |阅读模式
1Qter豆

最佳答案

查看完整内容

#include class EmptyDelegate : public QItemDelegate { public: EmptyDelegate(QObject *parent = 0) : QItemDelegate(parent) { } QWidget *createEditor(QWidget *pWidget, const QStyleOptionViewItem &option, const QModelIndex &index) const { return NULL; } }; // 代理改成下面 setItemDelegateForColumn(1, new EmptyDelegate(this));
回复

使用道具 举报

累计签到:12 天
连续签到:1 天
2016-1-27 17:17:37 显示全部楼层
#include <QItemDelegate>
class EmptyDelegate : public QItemDelegate
{
public:
        EmptyDelegate(QObject *parent = 0) : QItemDelegate(parent) { }
        QWidget *createEditor(QWidget *pWidget, const QStyleOptionViewItem &option, const QModelIndex &index) const
        {
                return NULL;
        }
};
// 代理改成下面
setItemDelegateForColumn(1, new EmptyDelegate(this));
回复

使用道具 举报

累计签到:12 天
连续签到:1 天
2016-1-27 17:32:15 显示全部楼层
假如是第1列
setItemDelegateForColumn(1, NULL);
回复

使用道具 举报

累计签到:70 天
连续签到:1 天
2016-1-28 09:22:38 显示全部楼层
shencj1234 发表于 2016-1-27 17:32
假如是第1列
setItemDelegateForColumn(1, NULL);

没管用呀; 这个代理传的是NULL,也就是可以不用自己定义代理是么?
回复

使用道具 举报

累计签到:27 天
连续签到:1 天
2016-3-1 17:46:16 显示全部楼层
//设置为只读
        for (int i = 0;i < 6; i++)
        {
                QItemDelegate readOnlyDelegate;  
                m_ui.tableView->setItemDelegateForColumn(i, &readOnlyDelegate);  
        }

我这是6列的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了