使用python迭代QListView中的所有项目 [英] Iterating all items inside QListView using python

查看:50
本文介绍了使用python迭代QListView中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 QlistView 里面有一个复选框(动态创建)和项目名称(QstandardItem).Qlistview 下面是一个名为 DatacheckercheckBox1 的复选框.我想要的是当此 DatacheckercheckBox1 复选框状态更改为已选中"时,应选中 QlistView 中的所有复选框.我已通过

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)

我不知道编写一个方法来迭代 Qlistview 中的所有项目,如果尚未选中,则将其旁边的复选框设为已选中".

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.

推荐答案

使用模型迭代项目:

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)

这篇关于使用python迭代QListView中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆