I have a QTableWidget with several columns that are just checkboxes (and some are not). I am trying to implement a function, so when the user right-clicks on the header element associated with the “only checkbox” column, they will be given the option to “remove all” or “check all”.
So far, I have managed to implement customContextMenu with the following signals:
self.headers = self.tblData.horizontalHeader() self.headers.setContextMenuPolicy(Qt.CustomContextMenu) self.headers.customContextMenuRequested.connect(self.show_header_context_menu) self.headers.setSelectionMode(QAbstractItemView.SingleSelection)
This leads to the following context menu call:
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
This displays the context menu, however I cannot find a way to get the index of the header that was right-clicked, I tried self.headers.selectedIndexes() as well as self.headers.currentIndex() , but they seem to apply only to selection of actual tables, not headers.
Once I manage to get the right-click header index, I can easily restrict the menu display only when choosing the right indexes (these columns are with only checkboxes), so actually it is.
What am I missing? Thanks in advance for any help.
source share