add treeWidget Demo

This commit is contained in:
weike32 2019-04-20 11:47:18 +08:00
parent 009e45ad0f
commit 79deb5c570
4 changed files with 3 additions and 48 deletions

View file

@ -11,9 +11,10 @@
![ParsingJson](ScreenShot/ParsingJson.png)
## 2、点击父节点全选/取消全选子节点
[运行 testTreeWidget.py](testTreeWidget.py)
点击父节点全选/取消全选子节点
![testTreeWidget](allSelect.png)
![testTreeWidget](ScreenShot/allSelectNode.png)

View file

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -1,47 +0,0 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'testTree.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(719, 544)
self.treeWidget = QtWidgets.QTreeWidget(Form)
self.treeWidget.setGeometry(QtCore.QRect(80, 80, 256, 192))
self.treeWidget.setObjectName("treeWidget")
item_0 = QtWidgets.QTreeWidgetItem(self.treeWidget)
item_0.setCheckState(0, QtCore.Qt.Unchecked)
item_1 = QtWidgets.QTreeWidgetItem(item_0)
item_1.setCheckState(0, QtCore.Qt.Unchecked)
item_1 = QtWidgets.QTreeWidgetItem(item_0)
item_1.setCheckState(0, QtCore.Qt.Unchecked)
item_1 = QtWidgets.QTreeWidgetItem(item_0)
item_1.setCheckState(0, QtCore.Qt.Unchecked)
item_1 = QtWidgets.QTreeWidgetItem(item_0)
item_1.setCheckState(0, QtCore.Qt.Unchecked)
item_1 = QtWidgets.QTreeWidgetItem(item_0)
item_1.setCheckState(0, QtCore.Qt.Unchecked)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.treeWidget.headerItem().setText(0, _translate("Form", "测试"))
__sortingEnabled = self.treeWidget.isSortingEnabled()
self.treeWidget.setSortingEnabled(False)
self.treeWidget.topLevelItem(0).setText(0, _translate("Form", "测试1"))
self.treeWidget.topLevelItem(0).child(0).setText(0, _translate("Form", "子节点1"))
self.treeWidget.topLevelItem(0).child(1).setText(0, _translate("Form", "字节点2"))
self.treeWidget.topLevelItem(0).child(2).setText(0, _translate("Form", "字节点3"))
self.treeWidget.topLevelItem(0).child(3).setText(0, _translate("Form", "字节点4"))
self.treeWidget.topLevelItem(0).child(4).setText(0, _translate("Form", "字节点5"))
self.treeWidget.setSortingEnabled(__sortingEnabled)

View file

@ -17,6 +17,7 @@ class graphAnalysis(QDialog,Ui_Form):
def __init__(self):
super(graphAnalysis, self).__init__()
self.setupUi(self)
# 点击父节点
self.treeWidget.itemChanged.connect(self.handleChanged)
def handleChanged(self,item,column):
count = item.childCount()