title: Access delegate class from QAction Trigger
body: <p>I have a QListWidget that categorizes items and its sub-items (they are all checkable).</p>
  
  <p>Currently while checking/unchecking the category items works properly for the sub items, I have introduced in a context menu in which the option should works the same way as you check and uncheck the category item.</p>
  
  <p>However in my <code>update_opts</code> - the QAction in the context menu, while it does allows me to check/uncheck the category item, but it does not effects the check-state of the sub items. </p>
  
  <p>Additionally, it seems that <code>QListWidgetItem</code> do not have a <code>trigger</code> or <code>toggle</code> signal that I could utilize to trigger the <code>editorEvent</code> in the delegate class.</p>
  
  <pre class="lang-py prettyprint-override"><code>IsCategoryRole = QtCore.Qt.UserRole
  ParentRole = QtCore.Qt.UserRole + 1
  
  
  class CategoryDelegate(QtGui.QStyledItemDelegate):
      def editorEvent(self, event, model, option, index):
          old_state = model.data(index, QtCore.Qt.CheckStateRole)
          res = super(CategoryDelegate, self).editorEvent(
              event, model, option, index
          )
          current_state = model.data(index, QtCore.Qt.CheckStateRole)
          if old_state != current_state:
              if index.data(IsCategoryRole):
                  pix = QtCore.QPersistentModelIndex(index)
                  for i in range(model.rowCount()):
                      ix = model.index(i, 0)
                      if pix == ix.data(ParentRole):
                          model.setData(
                              ix, current_state, QtCore.Qt.CheckStateRole
                          )
          return res
  
  
  class ListWidget(QtGui.QListWidget):
      def __init__(self, parent=None):
          super(ListWidget, self).__init__(parent)
          delegate = CategoryDelegate(self)
          self.setItemDelegate(delegate)
  
      def addCategory(self, text):
          item = ListWidget.create_checkable_item(text)
          item.setData(IsCategoryRole, True)
          self.addItem(item)
          return item
  
      def addItemToCategory(self, category_item, text):
          item = ListWidget.create_checkable_item(text)
          item.setData(IsCategoryRole, False)
          ix = self.indexFromItem(category_item)
          pix = QtCore.QPersistentModelIndex(ix)
          item.setData(ParentRole, pix)
          self.addItem(item)
          return item
  
      @staticmethod
      def create_checkable_item(text):
          item = QtGui.QListWidgetItem(text)
          item.setFlags(
              item.flags()
              | QtCore.Qt.ItemIsUserCheckable
              | QtCore.Qt.ItemIsEditable
          )
          item.setCheckState(QtCore.Qt.Unchecked)
          return item
  
      def mousePressEvent(self, event):
          if event.button() == QtCore.Qt.RightButton:
              list_menu = QtGui.QMenu(self)
              selected_item = self.currentItem()
              if selected_item.data(IsCategoryRole):
                  update_cat_items = QtGui.QAction("Check all or none", self)
                  update_cat_items.triggered.connect(self.update_opts)
                  list_menu.addAction(update_cat_items)
  
              list_menu.exec_(QtGui.QCursor().pos())
  
          else:
              super(ListWidget, self).mousePressEvent(event)
  
      def update_opts(self):
          selected_item = self.currentItem() 
          state = selected_item.checkState() # It returns eith 0 or 2, instead of QtCore.Qt.Unchecked or QtCore.Qt.Checked
  
          if state == QtCore.Qt.Checked:
              # If opt is checked in the first place, set it to uncheck
              selected_item.setCheckState(QtCore.Qt.Unchecked)
  
          else:
              # If opt is unchecked in the first place, set it to check
              selected_item.setCheckState(QtCore.Qt.Checked)
  
  
  class TestDialog(QtGui.QDialog):
      def __init__(self, parent=None):
          super(TestDialog, self).__init__()
          self.listWidget = ListWidget()
  
          all_num = self.listWidget.addCategory("-- All Nums --")
          num_items = ["One", "Two", "Three"]
          for num in num_items:
              self.listWidget.addItemToCategory(all_num, num)
  
          all_letters = self.listWidget.addCategory("-- All Letters --")
  
          letter_items = ["A", "B", "C"]
          for letter in letter_items:
              self.listWidget.addItemToCategory(all_letters, letter)
  
          layout = QtGui.QVBoxLayout(self)
          layout.addWidget(self.listWidget)
  
  
  
  
  if __name__ == "__main__":
      import sys
  
      app = QtGui.QApplication(sys.argv)
      w = TestDialog()
      w.show()
      sys.exit(app.exec_())
  </code></pre>