Adding signal on table items

  • Hi,

    I've built a QDialog with Qt 4 Designer that contains a QCheckBox that I want to enable for checking depending on a specific number of QTableWidget items being checked. I know I need to work with the signal system but the problem I have is that the QTableWidget in the .ui file is empty so in Designer I can only emit signals like itemClicked and e.g. click my QCheckBox.

    After loading the ui file, I populate the QTableWidget in Python with the first item on each row being checkable. What I need to do is enable the QCheckBox if two of my rows have their first item checked. If I could count the number of checked rows on each click and then decide what to do with the QCheckBox, that would be great. Here is what I need to do :

    if nb_first_row_cells_checked == 2:
    chk.setCheckState(Qt.Unchecked) # User can check
    else :
    chk.setCheckState(Qt.Unchecked) # Force uncheck if nb !=2

    Do I need a separate class to do that ?



  • You should be able to do what you need by connecting the QTableWidget::cellChanged or QTableWidget::itemChanged signal to something and check the checkbox state there keeping a count of checked checkboxes updated.

  • Thanx bsomervi. Good point. I could go with an even more general signal (like itemClicked) but finding the signal that will more rightly pick only a checkbox checked/unchecked action would be optimal.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.