擅长:python、mysql、java
<p>下面是另一个使用<a href="http://doc.qt.io/qt-5/qstandarditemmodel.html" rel="nofollow noreferrer">^{<cd1>}</a>的PyQt完整工作示例:</p>
<pre><code>model = QStandardItemModel()
parent_item = model.invisibleRootItem() # type: QStandardItem
for row in [
(Qt.Unchecked, 'unchecked'),
(Qt.PartiallyChecked, 'partially'),
(Qt.Checked, 'checked')
]:
checked, text = row
check_item = QStandardItem('')
check_item.setCheckable(True)
check_item.setCheckState(checked)
parent_item.appendRow([check_item, QStandardItem(text)])
treeview.setModel(model)
</code></pre>
<btw,这也适用于任何C++应用程序。</p>