mardi 6 octobre 2020

how to return the checked item in the qlistWidget in python

I have a python script that includes QlistWidget that has items with checkBox as

header_list["event_type","date","event_city"]

What i want is to return the checked items as the user checked mean:

if the user check event_city then event_type the result must be:

 self.checked=["event_city","event_type"]

for now the script return the result :

self.checked=["event_type","event_city"]

although the user he checked first the event_city value

enter image description here

Where is the error in my function?

def selectionChanged(self):
        self.checked = []
        if self.checked == 0:
            self.showMsg()
        else:
            for row in range(self.header_list.count()):
                item = self.header_list.item(row)
                #need to be checked in order to display the item in the order that the user choose.
                if item.checkState():
                    if item in self.checked:
                        del self.checked[item]
                    else:
                    # if not item in self.checked: 
                        self.checked.append(item)
                    
            # checked.insert(len(checked)-1,item)
            print("Checked items: ", ", ".join(i.text() for i in self.checked))
            self.checked = [i.text() for i in self.checked]
    



Aucun commentaire:

Enregistrer un commentaire