QtCore.Qt.ItemIsUserCheckable
-
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)
-
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. -
Thank both, i changed and just used a QCheckBox and setCellWidget, it is working for what i need it to do.
-
Thank both, i changed and just used a QCheckBox and setCellWidget, it is working for what i need it to do.
@Nightmaster
If you use your ownQCheckBox
es you can use QButtonGroup Class to add exclusiveness if you want. -
@Nightmaster
If you use your ownQCheckBox
es you can use QButtonGroup Class to add exclusiveness if you want.@JonB Yep have done that.
Thanks :)
-