Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QtCore.Qt.ItemIsUserCheckable
Forum Updated to NodeBB v4.3 + New Features

QtCore.Qt.ItemIsUserCheckable

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 4 Posters 632 Views 2 Watching
  • 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.
  • N Offline
    N Offline
    Nightmaster
    wrote on last edited by
    #1

    Hi All

    So i have some check boxes (using QtCore) in a QTableWidget that are added via QTableWidgetitem. Thing is I can't see how to make them exclusive, currently a user can check as many boxes as they like.
    I did try a qactiongroup but got the following error

    "TypeError: QActionGroup(QObject): argument 1 has unexpected type 'QTableWidgetItem'"

    This is my code..

            for data in self.get_appts:
                self.table.setRowCount(len(self.get_appts))
                self.table.setColumnCount(len(self.get_appts[0]))
                self.table.setItem(self.tab_row, 0, QTableWidgetItem(data[1]))
                self.table.setItem(self.tab_row, 1,QTableWidgetItem(data[2]))
                self.table.setItem(self.tab_row, 2, QTableWidgetItem(data[3]))
                self.table.setItem(self.tab_row, 3, QTableWidgetItem(data[4]))
                self.table.setHorizontalHeaderLabels(["Start Time", "End Time", "Location", "Doctor", "Select one"])
                self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
                self.check_item = QTableWidgetItem(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
                self.check_item.setCheckState(QtCore.Qt.Unchecked)
                qa = QActionGroup(self.check_item)
                qa.setExclusive(True)
                self.table.setItem(self.tab_row, 4, self.check_item)
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From the top of my head, you can't do that with your current setup.
      If you really need a table view, then you will have to implement a custom table model that will handle the exclusiveness part.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        It's probably easier to use the itemChanged signal to detect when an item is checked, and uncheck the previous item in a slot.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nightmaster
          wrote on last edited by
          #4

          Thank both, i changed and just used a QCheckBox and setCellWidget, it is working for what i need it to do.

          JonBJ 1 Reply Last reply
          0
          • N Nightmaster

            Thank both, i changed and just used a QCheckBox and setCellWidget, it is working for what i need it to do.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Nightmaster
            If you use your own QCheckBoxes you can use QButtonGroup Class to add exclusiveness if you want.

            N 1 Reply Last reply
            0
            • JonBJ JonB

              @Nightmaster
              If you use your own QCheckBoxes you can use QButtonGroup Class to add exclusiveness if you want.

              N Offline
              N Offline
              Nightmaster
              wrote on last edited by
              #6

              @JonB Yep have done that.

              Thanks :)

              1 Reply Last reply
              1
              • N Nightmaster has marked this topic as solved on

              • Login

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