self.sender() always None
-
I'm using PySide. I have a QTableWidget with QComboBoxes inside, which was done by using setCellWidget. I connect each combo box's currentIndexChanged signal to a slot. When I try to get the combo box that sent the signal using self.sender(), it's always None. Does anyone else have this problem?
-
Hi,
Can you show a minimal sample code that exhibit this behavior ?
-
What's weird is I tried the same code again today, but I'm getting the sender this time. Something is not right with how PySide passes the sender, but I can tell this is one of those bugs that will be really hard to track down since it's really inconsistent. Here's a simplified version of what I'm working with:
import sys from PySide.QtCore import * from PySide.QtGui import * class CustomDialog(QDialog): def __init__(self, parent=None): super(CustomDialog, self).__init__(parent) self.setLayout(QVBoxLayout()) self.table = QTableWidget() self.table.setColumnCount(2) self.layout().addWidget(self.table) self.table.setRowCount(10) for row in xrange(self.table.rowCount()): item = QTableWidgetItem(str(row)) self.table.setItem(row, 0, item) combo = QComboBox() combo.addItems(['one', 'two', 'three']) combo.currentIndexChanged.connect(self.onIndexChanged) self.table.setCellWidget(row, 1, combo) @Slot(int) def onIndexChanged(self, index): print self.sender() def main(): app = QApplication(sys.argv) dialog = CustomDialog() dialog.show() app.exec_() if __name__ == '__main__': main()
If you don't get the bug, I wouldn't spend too much time looking into it, but I appreciate the help.