QTableView 与选择模型()的问题
我对 QTableView.selectionModel() 的调用遇到问题。我在另一个类中实例化我的 QTableView,然后当我打开一个新项目并需要填充我的视图时,我调用一个函数 fillGrid(),在其中获取数据等。这也是我调用 SelectionModel() 方法的地方。
我第一次打电话时一切都很顺利。但是,如果我尝试在程序的同一实例中再次调用它,则会出现以下错误:
类型错误:“QItemSelectionModel”对象不可调用
我的函数 fillGrid 看起来像:
def fillGrid(self):
self.infos = select.getInfosProject(self.parent.db, self.parent.currentProj)
self.getData()
header = ["id","hidden","state","filename","asset-shot name","task","buffer","pass","camera","version","user","date","deps","check","comment","start frame","end frame","missing frames","edit start frame","edit end frame"]
self.model = SequenceGridModel(self.data, header, self)
self.setModel(self.model)
self.hideColumn(0)
self.hideColumn(1)
font = QtGui.QFont("Verdana", 8)
self.setFont(font)
vh = self.verticalHeader()
vh.setVisible(False)
hh = self.horizontalHeader()
hh.setStretchLastSection(True)
self.resizeColumnsToContents()
self.setSelectionBehavior(QtGui.QTableView.SelectRows)
self.selectionModel = self.selectionModel()
self.connect(self.selectionModel, QtCore.SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.getSelection)
self.setSortingEnabled(True)
self.setEditTriggers(QtGui.QAbstractItemView.CurrentChanged)
self.viewport().installEventFilter(self)
self.setItemDelegateForColumn(13,ComboBoxDelegate(self, self.checkValues))
self.setColumnWidth(13, 64)
知道为什么会发生这种情况吗? 提前致谢
I have a problem with my call to QTableView.selectionModel(). I instanciate my QTableView in another class, then when I open a new project and need to fill in my view I call a function fillGrid() in which I get the data among other things. This is also where I call the selectionModel() method.
Everything goes well the first time I call it. But if I try to call it again in the same instance of the program then it gives me the following error :
TypeError: 'QItemSelectionModel' object is not callable
my function fillGrid looks like :
def fillGrid(self):
self.infos = select.getInfosProject(self.parent.db, self.parent.currentProj)
self.getData()
header = ["id","hidden","state","filename","asset-shot name","task","buffer","pass","camera","version","user","date","deps","check","comment","start frame","end frame","missing frames","edit start frame","edit end frame"]
self.model = SequenceGridModel(self.data, header, self)
self.setModel(self.model)
self.hideColumn(0)
self.hideColumn(1)
font = QtGui.QFont("Verdana", 8)
self.setFont(font)
vh = self.verticalHeader()
vh.setVisible(False)
hh = self.horizontalHeader()
hh.setStretchLastSection(True)
self.resizeColumnsToContents()
self.setSelectionBehavior(QtGui.QTableView.SelectRows)
self.selectionModel = self.selectionModel()
self.connect(self.selectionModel, QtCore.SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.getSelection)
self.setSortingEnabled(True)
self.setEditTriggers(QtGui.QAbstractItemView.CurrentChanged)
self.viewport().installEventFilter(self)
self.setItemDelegateForColumn(13,ComboBoxDelegate(self, self.checkValues))
self.setColumnWidth(13, 64)
Any idea why this is happening ?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将 QItemSelectionModel 实例分配给名称选择模型,但选择模型是 QTableView 类的方法。您需要为您的选择模型选择一个新名称。请参阅 QAbstractItemView 类参考。
如果您想分配该选择模型以应用于您的模型,您需要使用 setSelectionModel 方法。
You've assigned your QItemSelectionModel instance to the name selectionModel, but selectionModel is a method of the QTableView class. You need to pick a new name for your selection model. See the QAbstractItemView class reference.
If you want to assign that selection model to apply to your model you need to use the setSelectionModel method.