title: Getting Header Column on Right Click for QTableWidget
body: <p>I have a QTableWidget with a number of columns that are only checkboxes (and some that aren't). I am trying to implement a feature so that when the user right clicks on a header item related to a "checkbox only" column, they are presented with the option to "uncheck all" or "check all".</p>
  
  <p>So far, I've managed to implement a <code>customContextMenu</code> via the following signals:</p>
  
  <pre><code>self.headers = self.tblData.horizontalHeader()
  self.headers.setContextMenuPolicy(Qt.CustomContextMenu)
  self.headers.customContextMenuRequested.connect(self.show_header_context_menu)
  self.headers.setSelectionMode(QAbstractItemView.SingleSelection)
  </code></pre>
  
  <p>Which leads to the following context menu call:</p>
  
  <pre><code>def show_header_context_menu(self, position):
      menu = QMenu()
      deselect = menu.addAction("Clear Checked")
      ac = menu.exec_(self.tblData.mapToGlobal(position))
      if ac == deselect:
          pass
          #Actually do stuff here, of course
  </code></pre>
  
  <p>This pops up a context menu, however I cannot find any way to get the index of the header that was right-clicked, I've tried <code>self.headers.selectedIndexes()</code> as well as <code>self.headers.currentIndex()</code> but these seem to only relate to the actual table selections, and not the headers.</p>
  
  <p>Once I manage to get the right-clicked header index, I can easily restrict the menu to show only when the right indexes are selected (those columns with only checkboxes), so that's an additional thing, really.</p>
  
  <p>What am I missing? Thanks in advance for any help.</p>