pyqt QTableWidgetItem connect signal

后端 未结 1 1345
后悔当初
后悔当初 2021-01-25 09:30

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         


        
相关标签:
1条回答
  • 2021-01-25 09:52

    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) 
    

    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
    ) 
    
    0 讨论(0)
提交回复
热议问题