mardi 25 juin 2019

How to check if a checkbox is checked in a qtablewidget?

I'm setting a filtering tool in Python 3.7 and I'm using pyqt5. I've created a qtablewidget to store the filters and their complementaries choosed by the user. I'd like to allow the user to combine filters over a data so I added grouped checkboxes in each row to select wanted filters. Which commands should I use to loop over my qtable to get wich checkbox is selected please ?

enter image description here

def bindApply(self):
    checked_list = []
    for i in range(self.tableWidget.rowCount()):
        #print(self.tableWidget.rowCount())
        if self.tableWidget.item(i, 1).checkState() == QtCore.Qt.Checked:
            checked_list.append([i,1])
        elif self.tableWidget.item(i, 2).checkState() == QtCore.Qt.Checked:
            checked_list.append([i,2])
        else:
            pass
    return(checked_list)

I expect a list containg the indexes of selected rows and columns but my function returns nothing.




Aucun commentaire:

Enregistrer un commentaire