python-3.x - PySide/PyQt : 'TypeError: native Qt signal is not callable' when trying to use 'currentItemChanged' with QTableWidget

标签 python-3.x pyqt pyside qtablewidget qtablewidgetitem

我有一个包含一些数据的表格,我希望能够通过 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/

相关文章:

python - PyQt - 实现 QAbstractTableModel 以在 QTableView 中显示

python - PYQT Graphics 查看图像的像素值

python - PyQt5 布局的不等部分

python - PySide 代替 PyQt4 作为 matplotlib Qt4Agg 后端的先决条件

python - python 3中long int除法的区别

python - 如何在 python 中的同一图形上以升序绘制压缩列表的前 5 和后 5?

python - on_load 清除某个 channel 的所有消息

Python/QT - 我该怎么做才能在一系列小部件之间获得 4 个像素边框?

python - 正确使用QTimer.singleShot

python-3.x - Sympy:如何解析 '2x' 等表达式?