pyqt QTableWidgetItem 连接信号 [英] pyqt QTableWidgetItem connect signal

查看:152
本文介绍了pyqt QTableWidgetItem 连接信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更改单元格中的值时,我试图让我的 QTableWidget 调用一些函数.

I'm trying to make my QTableWidget call some function when I change the values in a cell.

self.table = QtGui.QTableWidget()  
tableItem = QtGui.QTableWidgetItem( str(attr.GetValue()) )
self.table.setItem(row, 1, tableItem )
QtCore.QObject.connect(self.table, QtCore.SIGNAL('currentItemChanged(QTableWidgetItem*, QTableWidgetItem*)'), someFunc)  

我的问题是,在我对单元格进行值更改之前,它会在我进入单元格后立即调用该函数.此外,它出于某种奇怪的原因调用了该函数两次.

My problem is that it calls the function as soon as I enter the cell before I've even made value changes to it. Also it calls the function twice for some weird reason.

推荐答案

我认为您使用了错误的信号.currentItemChanged 指的是选择.不适用于数据更改时.尝试使用 itemChanged:

I think you are using the wrong signal. currentItemChanged refers to selection. Not for when the data changes. Try using itemChanged:

self.table.itemChanged.connect(someFunc) 

另请注意,我正在使用 新型信号槽 是在 Qt 4.5 中引入的.您不必再为指定 C++ 签名而烦恼了.

Notice also that I am using the new-style signal slots that were introduced back in Qt 4.5. You don't have to go to all that trouble anymore of specifying the C++ signature.

至于你的信号多次触发,要么是因为每次选择改变时它都会触发而你没有意识到,要么你成功地多次连接它.

As for your signal firing multiple times, it either was because it was firing every time the selection changed and you didn't realize it, or you managed to connect it more than once.

作为参考,连接这个信号的旧式语法是:

For reference, the old style syntax for connecting this signal is:

QtCore.QObject.connect(
    self.table, 
    QtCore.SIGNAL('itemChanged(QTableWidgetItem*)'), 
    someFunc
) 

这篇关于pyqt QTableWidgetItem 连接信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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