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

  • Home
  • SEARCH
  • 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 3211550
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:44:43+00:00 2026-05-17T14:44:43+00:00

I have a dynamically created table, that has N rows and M QTableWidgetItems (that

  • 0

I have a dynamically created table, that has N rows and M QTableWidgetItems (that are only used as checkboxes) per row – I need to run code that knows the row and the column whenever a checkbox is checked or unchecked.

My CheckBox subclass looks like:

class CheckBox(QTableWidgetItem):
    def __init__(self):
        QTableWidgetItem.__init__(self,1000)
        self.setTextAlignment(Qt.AlignVCenter | Qt.AlignJustify)
        self.setFlags(Qt.ItemFlags(
            Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled ))
def stateChanged(self):
    do_something(self.row(),self.column())
    ...

Obviously this does not redefine the function that gets called when SIGNAL('stateChanged(int)') -thingy happens, because, well, nothing happens.

But, if I do:

item = CheckBox()
self.connect(item, SIGNAL('stateChanged(int)'), item.stateChanged)

In the loop creating the table, I get an error:

TypeError: arguments did not match any overloaded call:
  QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'CheckBox'
  QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'CheckBox'
  QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'CheckBox

EDIT:
I also tried redefining setCheckState() but apparently that does NOT get called when the item is checked or unchecked.

EDIT 2:
Furthermore, changing the connect to

self.connect(self.table, SIGNAL('itemClicked(item)'),
               self.table.stateChanged)

where table = QTableWidget() does not help either.

How do I do this the right way?

  • 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-05-17T14:44:44+00:00Added an answer on May 17, 2026 at 2:44 pm

    The simplest solution is probably connecting to the cellChanged(int, int) signal of the QTableWidget; take a look at the following example:

    import sys
    from PyQt4.QtGui import *
    from PyQt4.QtCore import *
    
    #signal handler
    def myCellChanged(row, col):
        print row, col
    
    #just a helper function to setup the table
    def createCheckItem(table, row, col):
        check = QTableWidgetItem("Test")
        check.setCheckState(Qt.Checked)
        table.setItem(row,col,check)
    
    app = QApplication(sys.argv)
    
    #create the 5x5 table...
    table = QTableWidget(5,5)
    map(lambda (row,col): createCheckItem(table, row, col),
       [(row, col) for row in range(0, 5) for col in range(0, 5)])
    table.show()
    
    #...and connect our signal handler to the cellChanged(int, int) signal
    QObject.connect(table, SIGNAL("cellChanged(int, int)"), myCellChanged)
    app.exec_()
    

    It creates a 5×5 table of checkboxes; whenever one of them is checked/unchecked, myCellChanged is called and prints the row and column of the changed checkbox; you can then of course use QTableWidget.item(someRow, someColumn).checkState() to see whether it was checked or unchecked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that I am trying to dynamically delete rows from. Each
I have a table of paged data, along with a dynamically created pager (server-side
I have a dynamically created image that I am saving to a stream so
I have a button that will create a new entry (row in a table)
I have a table which has a button to Add Rows. This button adds
Here's the situation: I have a menu that needs to be created dynamically from
I have a script that appends some rows to a table. One of the
I have some dynamically created inputs which are not server-side controls. I want to
I have a link that I dynamically create which looks something like the following:
I have written a CGI script that creates an image dynamically using GET data.

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.