title: fire signal when qtreewidgetitems checkbox state changes
body: <p>I have a simple example here. What I want to happen is when a user changes the toggle state of the 'Checkbox' i want it to set the property value for the CustomTreeWidgetItem's attr.</p>
  
  <p>In this case each CustomTreeWidgetItem has an attr called dataObject which is where I store my class object Family. Family has an attribute <strong>enabled</strong> which I want this property to reflect the toggle state of the TreeWidgetItems' checkbox.</p>
  
  <p>I have looked around online and have not found a solution yet for this. Most answers were in c++ or they were causing errors.  You can test the results by clicking the print button. It should reflect the changes.</p>
  
  <p>Here are the highlighted bits.</p>
  
  <p><strong>Updated:</strong>
  The linked question does not answer my question. It does not return the value for the checkbox clicked.</p>
  
  <p>What is this code doing in simple terms? And what do i need to modify to make it set the data object to True or False? Currently it returns 0 or 2. I'm not sure if that is tristate or what. Hope someone can explain what is going on. </p>
  
  <pre><code>if column == 0 and role == 10:
  </code></pre>
  
  <p>My custom tree widget items have the property <strong>dataObject</strong>. This is where I store my class object <strong>Family</strong> which has the property <strong>enabled</strong> in it.</p>
  
  <pre><code>self.dataObject = None
  
  class Family:
      def __init__(self, name, members=None, data=None):
          self.name = name
          self.enabled = True
  </code></pre>
  
  <p>Hope that helps.</p>
  
  <p>Thanks</p>
  
  <p><a href="https://i.stack.imgur.com/K2vSM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K2vSM.png" alt="enter image description here"></a></p>
  
  <p><strong>all the code</strong></p>
  
  <pre><code># Imports
  # ------------------------------------------------------------------------------
  import sys
  from PySide import QtGui, QtCore
  
  # Class
  # ------------------------------------------------------------------------------
  class Family:
      def __init__(self, name, members=None, data=None):
          self.name = name
          self.enabled = True
  
  
  # Custom Tree Widget
  # ------------------------------------------------------------------------------
  class TreeNodeItem( QtGui.QTreeWidgetItem ):
  
      def __init__( self, parent, name ):
  
          ## Init super class ( QtGui.QTreeWidgetItem )
          super( TreeNodeItem, self ).__init__( parent )
  
          # Column 0 - Text:
          self.setText( 0, name )
  
          # Tree Node Data
          self.dataObject = None
  
      def setData(self, column, role, value):
          if column == 0 and role == 10:
              self.dataObject.enabled = value
  
          super(TreeNodeItem, self).setData(column, role, value)
  
  
  # Variables
  # ------------------------------------------------------------------------------
  Families = [
      Family("Smith"), 
      Family("Michaels"),
      Family("Wislon"), 
      Family("Yoder")
  ]
  
  # Main
  # ------------------------------------------------------------------------------
  class Example(QtGui.QWidget):
  
      def __init__(self,):
          super(Example, self).__init__()
  
          self.initUI()
  
      def initUI(self):
  
          # formatting
          self.resize(400, 400)
          self.setWindowTitle("Example")
  
          # widgets
          self.printData = QtGui.QPushButton("Print Families Data")
          self.itemList = QtGui.QTreeWidget()
          self.itemList.setItemsExpandable(True)
          self.itemList.setAnimated(True)
          self.itemList.setItemsExpandable(True)
          self.itemList.setColumnCount(1)
          self.itemList.setHeaderLabels(['Families'])
  
          # signals
          self.printData.clicked.connect(self.PrintAllData)
  
          # layout - row/column/verticalpan/horizontalspan
          self.mainLayout = QtGui.QGridLayout(self)
          self.mainLayout.addWidget(self.itemList,0,0)
          self.mainLayout.addWidget(self.printData,1,0)
  
          self.center()
          self.show()
          self.UpdateFamilies()
  
      def center(self):
  
          qr = self.frameGeometry()
          cp = QtGui.QDesktopWidget().availableGeometry().center()
          qr.moveCenter(cp)
          self.move(qr.topLeft())
  
      def PrintAllData(self):
          for f in Families:
              print f.name, f.enabled
  
      def UpdateFamilies(self):
          treeWidget = self.itemList
          treeWidget.clear()
  
          for f in Families:
              # Add Families
              treeNode = TreeNodeItem(treeWidget, f.name)
              # assign family class object to dataObject attr of treenode
              treeNode.dataObject = f
              treeNode.setCheckState(0, QtCore.Qt.Checked)
  
  # Main
  # ------------------------------------------------------------------------------
  if __name__ == "__main__":
      app = QtGui.QApplication(sys.argv)
      ex = Example()
      sys.exit(app.exec_())
  </code></pre>