PySide/PyQt: 'TypeError: native Qt signal is not callable' when trying to use 'currentItemChanged' with QTableWidget

浪尽此生 提交于 2019-12-23 19:15:15

问题


I have a table with some data that I want to be able to edit through the QTableWidget. Upon trying to connect the currentItemChanged signal:

self.QTableWidget.currentItemChanged(QTableWidgetItem,QTableWidgetItem).connect(self.editCell)

I get the following error:

'TypeError: native Qt signal is not callable' 

I went looking in to the QtDesigner, where you can connect signals. I made a QTableWidget, and connected it to a label so that changing the currentItem hid the label.

In the signal connecting dialog the currentItemChanged signal was written thus:

currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)

I don't know what the * means, but I assume it's important.

Am I using the wrong signal or is my syntax wrong somehow? In short, I want there a signal to be emitted upon changing any particular item/cell(I'm not sure what the distinction is)

____________________EDIT_________________________

EDIT: In the QTableWidgetItem class documentation I also found that it has functions column() and row().

I tried adding them like this:

self.QTableWidget.currentItemChanged(QTableWidgetItem.column(QTableWidgetItem.column()),QTableWidgetItem.row()).connect(self.editCell)

But got the error:

TypeError: descriptor 'column' requires a 'PySide.QtGui.QTableWidgetItem' object but received a 'Shiboken.ObjectType

回答1:


This bit is concerning:

self.QTableWidget

If your table is literally called "QTableWidget" there may be confusion later on. Specifically, the error you are getting makes it look like you are calling QTableWidget.currentItemChanged.

Also, its worth reviewing the PyQT documentation on "new-style signals", specifically on dealing with overloads to understand how it all works. Fortunately however, QTableWidget.currentItemChanged isn't overloaded so, the code you should be using should just be:

self.yourTable.currentItemChanged.connect(self.editCell)

Regarding your later edits, in this code:

currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)

The QTableWidgetItems that are being parsed are arguments that are given to the signal. You can't change them, as they are definined in the method that defines the slot, and passed when the signal is fired. From the documentation linked above:

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.



来源:https://stackoverflow.com/questions/19301489/pyside-pyqt-typeerror-native-qt-signal-is-not-callable-when-trying-to-use-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!