From 009e45ad0f8499d1fa5696cd8f65be9e75550959 Mon Sep 17 00:00:00 2001 From: weike32 <394967319@qq.com> Date: Sat, 20 Apr 2019 11:32:46 +0800 Subject: [PATCH] add treeWidget Demo --- .idea/PyQt.iml | 7 ++- .idea/misc.xml | 2 +- QTreeWidget/README.md | 10 +++- QTreeWidget/ScreenShot/allSelect.png | Bin 0 -> 15374 bytes QTreeWidget/testTree.py | 47 +++++++++++++++ QTreeWidget/testTree.ui | 82 +++++++++++++++++++++++++++ QTreeWidget/testTreeWidget.py | 35 ++++++++++++ 7 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 QTreeWidget/ScreenShot/allSelect.png create mode 100644 QTreeWidget/testTree.py create mode 100644 QTreeWidget/testTree.ui create mode 100644 QTreeWidget/testTreeWidget.py diff --git a/.idea/PyQt.iml b/.idea/PyQt.iml index b38140f..c8e73a1 100644 --- a/.idea/PyQt.iml +++ b/.idea/PyQt.iml @@ -1,8 +1,11 @@ - - + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index efebe5b..e454a58 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -56,5 +56,5 @@ - + \ No newline at end of file diff --git a/QTreeWidget/README.md b/QTreeWidget/README.md index 7412edc..f47b05a 100644 --- a/QTreeWidget/README.md +++ b/QTreeWidget/README.md @@ -2,10 +2,18 @@ - 目录 - [通过json数据生成树形结构](#1、通过json数据生成树形结构) + - [点击父节点全选/取消全选子节点](#2、点击父节点全选/取消全选子节点) ## 1、通过json数据生成树形结构 [运行 ParsingJson.py](ParsingJson.py) 解析每一层json数据中的list -![ParsingJson](ScreenShot/ParsingJson.png) \ No newline at end of file + +![ParsingJson](ScreenShot/ParsingJson.png) +## 2、点击父节点全选/取消全选子节点 +[运行 testTreeWidget.py](testTreeWidget.py) + +点击父节点全选/取消全选子节点 + +![testTreeWidget](allSelect.png) \ No newline at end of file diff --git a/QTreeWidget/ScreenShot/allSelect.png b/QTreeWidget/ScreenShot/allSelect.png new file mode 100644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9zrrd@vfk78k=vdoDK(w}cOs^2K*Udj%0Y^PdM;2n zNRefWQhjj>2w)79lTA#e_i0;009&I|Ot)~{m zU_9gK>B9G8OH+NeWe_E(e?9EMO|wT+i-L{5vLF&`Y4!Ewt)N<2CzBdRp76y zVj!EXqA~wGfCAv_KN&~;H<0T0D;Wp3gCZp=cb1}{&6ka7!$4r_>?#2XndSspB@xi< z0Ct}gJgE+-$=4D0E>o!?Wv=(PN5(Ww)aC+OHr;|V+7u``dJ_=BK8)lB{Q4Havihz* zqfIA!fV5g5TuG;*{@;L5@U>j~1J%QV(SQ|DV=~IAB^^VKK}*PX*K? z5j_CCyIEzhK?BFv066B{KYo!4jvs(h*t24!Ov7QIGyB^m@g@z2ffIQ`zI$gV$`}37 zuYeNs&^-Gt4MqUM&OE02gEm3E4&d-RlPlETj`?rkK+x}3{r3#WMZYvyoUCA5u1zbL zg5^z}JisZx9zNsWegU|`|75hiKWyIizq$5=#zl@qFw;Z!fgfRLTsDsRMILP;-pcWU z{}=^j)52d32>E#S?v`mWwGA-|cHZ9X4fJ|%ZG*YBx8Zfjw`Y7oh zEl_~d#6n*9xBApfqX)=+L~6D%Ez`_^OdD1H{VD*1{+$7P!e>ZI5pDOcQVlA2(ok?N z<^U$=sea9}^OvgxX|C!Q&!#a($}xjU>=ihbF&+huvCzxte4@GPGvKP~Ky4ahi~ty; zTIW65lbL~`+)`OAGBs6hm54vw;Z|%_?_<&tvmX+i*DLH F{U?Nro=yM& literal 0 HcmV?d00001 diff --git a/QTreeWidget/testTree.py b/QTreeWidget/testTree.py new file mode 100644 index 0000000..b317521 --- /dev/null +++ b/QTreeWidget/testTree.py @@ -0,0 +1,47 @@ +# -*- 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) + diff --git a/QTreeWidget/testTree.ui b/QTreeWidget/testTree.ui new file mode 100644 index 0000000..8ceab90 --- /dev/null +++ b/QTreeWidget/testTree.ui @@ -0,0 +1,82 @@ + + + Form + + + + 0 + 0 + 719 + 544 + + + + Form + + + + + 80 + 80 + 256 + 192 + + + + + 测试 + + + + + 测试1 + + + Unchecked + + + + 子节点1 + + + Unchecked + + + + + 字节点2 + + + Unchecked + + + + + 字节点3 + + + Unchecked + + + + + 字节点4 + + + Unchecked + + + + + 字节点5 + + + Unchecked + + + + + + + + diff --git a/QTreeWidget/testTreeWidget.py b/QTreeWidget/testTreeWidget.py new file mode 100644 index 0000000..49e931c --- /dev/null +++ b/QTreeWidget/testTreeWidget.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# encoding: utf-8 +''' +Created on 2017年4月20日 +@author: weike32 +@site: https://pyqt5.com , https://github.com/weike32 +@email: 394967319@qq.com +@file: CopyContent +@description: +''' +import sys +from PyQt5.QtCore import Qt +from PyQt5.QtWidgets import QDialog, QApplication +from QTreeWidget.testTree import Ui_Form + +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() + if item.checkState(column) == Qt.Checked: + for index in range(count): + item.child(index).setCheckState(0,Qt.Checked) + if item.checkState(column) == Qt.Unchecked: + for index in range(count): + item.child(index).setCheckState(0,Qt.Unchecked) + + +if __name__ =="__main__": + app = QApplication(sys.argv) + w = graphAnalysis() + w.show() + sys.exit(app.exec_()) \ No newline at end of file