Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterating all items inside QListView using python

I have a QlistView inside is which a checkboxes (created dynamically) with item name (QstandardItem). And below Qlistview is a checkbox named DatacheckercheckBox1. What I want is when this DatacheckercheckBox1 checkbox statechanges to "Checked", all the checkboxes inside the QlistView should be checked. I have made a signal for DatacheckercheckBox1 checkbox by

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

i dont have idea in writing a method that should iterate all the items inside Qlistview and make the checkboxes next to it "Checked" if its not checked already.

like image 269
harinish Avatar asked May 06 '15 11:05

harinish


1 Answers

Use the model to iterate over the 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)
like image 121
ekhumoro Avatar answered Nov 14 '22 23:11

ekhumoro