title: How do I get some slot/function to be executed when a certain QTableWidgetItem is checked / unchecked in PyQt
body: <p>I have a dynamically created table, that has N rows and M QTableWidgetItems (that are only used as checkboxes) per row - I need to run code that knows the row and the column whenever a checkbox is checked or unchecked.</p>
  
  <p>My CheckBox subclass looks like:</p>
  
  <pre><code>class CheckBox(QTableWidgetItem):
      def __init__(self):
          QTableWidgetItem.__init__(self,1000)
          self.setTextAlignment(Qt.AlignVCenter | Qt.AlignJustify)
          self.setFlags(Qt.ItemFlags(
              Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled ))
  def stateChanged(self):
      do_something(self.row(),self.column())
      ...
  </code></pre>
  
  <p>Obviously this does not redefine the function that gets called when  <code>SIGNAL('stateChanged(int)')</code> -thingy happens, because, well, nothing happens.</p>
  
  <p>But, if I do:</p>
  
  <pre><code>item = CheckBox()
  self.connect(item, SIGNAL('stateChanged(int)'), item.stateChanged)
  </code></pre>
  
  <p>In the loop creating the table, I get an error:</p>
  
  <pre><code>TypeError: arguments did not match any overloaded call:
    QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'CheckBox'
    QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'CheckBox'
    QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'CheckBox
  </code></pre>
  
  <p><strong>EDIT</strong>:
  I also tried redefining <code>setCheckState()</code> but apparently that does <em>NOT</em> get called when the item is checked or unchecked.</p>
  
  <p><strong>EDIT 2</strong>:
  Furthermore, changing the connect to </p>
  
  <pre><code>self.connect(self.table, SIGNAL('itemClicked(item)'),
                 self.table.stateChanged)
  </code></pre>
  
  <p>where <code>table = QTableWidget()</code> does not help either.</p>
  
  <p>How do I do this the right way?</p>