Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Adding signal on table items

    General and Desktop
    qt4.8 qtablewidget pyqt4
    2
    3
    1816
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      yvesm last edited by

      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.setEnabled(True)
      chk.setCheckable(True)
      chk.setCheckState(Qt.Unchecked) # User can check
      else :
      chk.setCheckState(Qt.Unchecked) # Force uncheck if nb !=2
      chk.setCheckable(False)
      chk.setEnabled(False)

      Do I need a separate class to do that ?

      TIA,

      Yves

      1 Reply Last reply Reply Quote 0
      • B
        bsomervi last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • Y
          yvesm last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post