Iterating all items inside a QListView using python

What I have QlistView

inside is checkboxes (generated dynamically) with element name ( QstandardItem

). And below QlistView

the checkbox is checked DatacheckercheckBox1

. I want this checkbox to DatacheckercheckBox1

change to Checked, all checkboxes inside QlistView

must be checked. I made a signal for a DatacheckercheckBox1

checkbox

self.dlg.DatacheckercheckBox1.stateChanged.connect(self.selectAll)

      

I have no idea to write a method that should iterate over all the elements inside QlistView

and check the boxes next to it "Checked" if it is not already checked.

+3


source to share


1 answer


Use a model to iterate over items:



model = self.listView.model()
for index in range(model.rowCount()):
    item = model.item(index)
    if item.isCheckable() and item.checkState() == QtCore.Qt.Unchecked:
        item.setCheckState(QtCore.Qt.Checked)

      

+3


source







All Articles