Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:09:38+00:00 2026-06-09T13:09:38+00:00

I have a QTableWidget with a number of columns that are only checkboxes (and

  • 0

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”.

So far, I’ve managed to implement a customContextMenu via 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)

Which 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
        #Actually do stuff here, of course

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 self.headers.selectedIndexes() as well as self.headers.currentIndex() but these seem to only relate to the actual table selections, and not the headers.

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.

What am I missing? Thanks in advance for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:09:39+00:00Added an answer on June 9, 2026 at 1:09 pm

    The customContextMenuRequested signal sends the position of the context menu event as a QPoint. Conveniently, the table’s headers have an overload of logicalIndexAt that can directly exploit that, so you can simply do:

    def show_header_context_menu(self, position):
        column = self.headers.logicalIndexAt(position)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's consider we have QWidget that contains QTableWidget (only). So we want to resize
I have tried to re-implement the QTableWidget.cellActivated(row, number) using PyQt4, to catch the coordinates
Have written the following code: m_selectCategoryTableWidget = new QTableWidget; m_selectCategoryTableWidget->setRowCount(0); m_selectCategoryTableWidget->setColumnCount(2); m_selectCategoryTableWidget->setHorizontalHeaderLabels(QStringList()<<tr(Category)<<tr(Number of items));
I have a QTableWidget and would like that pressing Ctrl while clicking on a
Say I have a QTableWidget with 10 columns. I set data in the table
I have a QTableWidget. In its cells I need to display 3-state QSliders, that
I have a QTableWidget that I populate like this: // Clear the table this->topPatchesTableWidget->setRowCount(0);
I'd like to have a QTableWidget that has 2 'header' rows. Essentially I'd like
QTableWidget have a method to search for a row with user data? Something like:
I have a QTableWidget in my program that I use to display results and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.