PySide/PyQt:尝试在QTableWidget中使用"currentItemChanged"时,"TypeError:本机Qt信号不可调用" [英] PySide/PyQt: 'TypeError: native Qt signal is not callable' when trying to use 'currentItemChanged' with QTableWidget

查看:653
本文介绍了PySide/PyQt:尝试在QTableWidget中使用"currentItemChanged"时,"TypeError:本机Qt信号不可调用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中包含一些我希望能够通过QTableWidget编辑的数据.尝试连接currentItemChanged信号时:

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)

我收到以下错误:

'TypeError: native Qt signal is not callable' 

我去看了QtDesigner,您可以在其中连接信号.我制作了QTableWidget,并将其连接到标签,以便更改currentItem可以隐藏标签.

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.

在信号连接对话框中,currentItemChanged信号被这样写:

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_________________________

在QTableWidgetItem类文档中,我还发现它具有函数column()和row().

In the QTableWidgetItem class documentation I also found that it has functions column() and 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.

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.

此外,值得回顾的新型信号"上的PyQT文档处理超载以了解其工作原理.不过,幸运的是, 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*)

正在解析的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:

无效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.

这篇关于PySide/PyQt:尝试在QTableWidget中使用"currentItemChanged"时,"TypeError:本机Qt信号不可调用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆