Search code examples
pythonpyqtpyqt4pyqt5

Parameter in PyQt connect


The examples I have seen about converting PyQt4 signals/slots to PyQt5 are pretty simple, such as connecting a button click to changing a label. But how should the following statement be converted:

self.connect(self.tableWidget,
    SIGNAL("itemChanged(QTableWidgetItem*)"),
    self.tableItemChanged)

It is the parameter to itemChanged that is confusing me. I tried, by analogy to the examples:

self.tableWidget.itemChanged(
    QTableWidgetItem*).connect(self.tableItemChanged)

Thanks!


Solution

  • When you make a new syntax connection there is no need to indicate the type of argument that the signal sends unless there are signals with the same name in the same class, but in your case it is not, so the following would be the solution:

    self.tableWidget.itemChanged.connect(self.tableItemChanged)
    

    The typical example of the exception is the QComboBox: the activated signal can send the string of the activated item or the index of the activated item, so there is to indicate the type of data that we want.

    combobox.activated[str].connect(self.handle_string)
    combobox.activated[int].connect(self.handle_int)