Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding signal on table items
Forum Updated to NodeBB v4.3 + New Features

Adding signal on table items

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt4.8qtablewidgetpyqt4
3 Posts 2 Posters 2.2k Views
  • 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 Offline
    Y Offline
    yvesm
    wrote on 13 Jan 2016, 22:49 last edited by
    #1

    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
    0
    • B Offline
      B Offline
      bsomervi
      wrote on 13 Jan 2016, 23:52 last edited by
      #2

      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
      0
      • Y Offline
        Y Offline
        yvesm
        wrote on 14 Jan 2016, 13:38 last edited by
        #3

        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
        0

        1/3

        13 Jan 2016, 22:49

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved