站长资源脚本专栏

PyQt5 QTableView设置某一列不可编辑的方法

整理:jimmy2025/3/11浏览2
简介如下所示:class EmptyDelegate(QItemDelegate):def __init__(self,parent):super(EmptyDelegate, self).__init__(parent)def createEditor(self, QWidget, QStyleOpt

如下所示:

class EmptyDelegate(QItemDelegate):
  def __init__(self,parent):
    super(EmptyDelegate, self).__init__(parent)
 
  def createEditor(self, QWidget, QStyleOptionViewItem, QModelIndex):
    return None

写一个代理。

self.tableView.setItemDelegateForColumn(2,EmptyDelegate(self)) # 设置第二列不可编辑

设置一下就可以了。

以上这篇PyQt5 QTableView设置某一列不可编辑的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。