我有一个包含一些数据的表格,我希望能够通过 QTableWidget
对其进行编辑。尝试连接 currentItemChanged
信号时:
self.QTableWidget.currentItemChanged(QTableWidgetItem,QTableWidgetItem).connect(self.editCell)
我收到以下错误:
'TypeError: native Qt signal is not callable'
我查看了 QtDesigner
,您可以在其中连接信号。我制作了一个 QTableWidget
,并将它连接到一个标签,以便更改 currentItem
隐藏标签。
在信号连接对话框中,currentItemChanged
信号是这样写的:
currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)
我不知道 *
是什么意思,但我认为它很重要。
是我使用了错误的信号还是我的语法有问题?简而言之,我希望在更改任何特定项目/单元格时发出信号(我不确定区别是什么)
____________________编辑___< em>______________________
编辑:在 QTableWidgetItem 类文档中,我还发现它具有函数 column() 和 row()。
我试过这样添加它们:
self.QTableWidget.currentItemChanged(QTableWidgetItem.column(QTableWidgetItem.column()),QTableWidgetItem.row()).connect(self.editCell)
但出现错误:
TypeError: descriptor 'column' requires a 'PySide.QtGui.QTableWidgetItem' object but received a 'Shiboken.ObjectType
最佳答案
这一点是关于:
self.QTableWidget
如果您的表字面意思是“QTableWidget”,那么以后可能会造成混淆。具体来说,您收到的错误让您看起来像是在调用 QTableWidget.currentItemChanged
。
此外,值得查看 "new-style signals", specifically on dealing with overloads 上的 PyQT 文档了解这一切是如何运作的。然而幸运的是,QTableWidget.currentItemChanged
没有重载,您应该使用的代码应该是:
self.yourTable.currentItemChanged.connect(self.editCell)
关于您以后的编辑,在此代码中:
currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)
被解析的 QTableWidgetItem
是提供给信号的参数。您不能更改它们,因为它们是在定义插槽的方法中定义的,并在信号被触发时传递。从上面链接的文档中:
void currentItemChanged (QTableWidgetItem *,QTableWidgetItem *)
This signal is emitted whenever the current item changes. The previous item is the item that previously had the focus, current is the new current item.
关于python-3.x - PySide/PyQt : 'TypeError: native Qt signal is not callable' when trying to use 'currentItemChanged' with QTableWidget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19301489/