add treeWidget Demo
This commit is contained in:
parent
4e3d4f6a27
commit
009e45ad0f
7 changed files with 179 additions and 4 deletions
|
@ -1,8 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.4" jdkType="Python SDK" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.5 (venv) (6)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
|
|
|
@ -56,5 +56,5 @@
|
|||
</profile-state>
|
||||
</entry>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.4" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5 (venv) (6)" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -2,10 +2,18 @@
|
|||
|
||||
- 目录
|
||||
- [通过json数据生成树形结构](#1、通过json数据生成树形结构)
|
||||
- [点击父节点全选/取消全选子节点](#2、点击父节点全选/取消全选子节点)
|
||||
|
||||
## 1、通过json数据生成树形结构
|
||||
[运行 ParsingJson.py](ParsingJson.py)
|
||||
|
||||
解析每一层json数据中的list
|
||||
|
||||
![ParsingJson](ScreenShot/ParsingJson.png)
|
||||
|
||||
![ParsingJson](ScreenShot/ParsingJson.png)
|
||||
## 2、点击父节点全选/取消全选子节点
|
||||
[运行 testTreeWidget.py](testTreeWidget.py)
|
||||
|
||||
点击父节点全选/取消全选子节点
|
||||
|
||||
![testTreeWidget](allSelect.png)
|
BIN
QTreeWidget/ScreenShot/allSelect.png
Normal file
BIN
QTreeWidget/ScreenShot/allSelect.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
47
QTreeWidget/testTree.py
Normal file
47
QTreeWidget/testTree.py
Normal file
|
@ -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)
|
||||
|
82
QTreeWidget/testTree.ui
Normal file
82
QTreeWidget/testTree.ui
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>719</width>
|
||||
<height>544</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>80</y>
|
||||
<width>256</width>
|
||||
<height>192</height>
|
||||
</rect>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>测试</string>
|
||||
</property>
|
||||
</column>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>测试1</string>
|
||||
</property>
|
||||
<property name="checkState">
|
||||
<enum>Unchecked</enum>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>子节点1</string>
|
||||
</property>
|
||||
<property name="checkState">
|
||||
<enum>Unchecked</enum>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>字节点2</string>
|
||||
</property>
|
||||
<property name="checkState">
|
||||
<enum>Unchecked</enum>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>字节点3</string>
|
||||
</property>
|
||||
<property name="checkState">
|
||||
<enum>Unchecked</enum>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>字节点4</string>
|
||||
</property>
|
||||
<property name="checkState">
|
||||
<enum>Unchecked</enum>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>字节点5</string>
|
||||
</property>
|
||||
<property name="checkState">
|
||||
<enum>Unchecked</enum>
|
||||
</property>
|
||||
</item>
|
||||
</item>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
35
QTreeWidget/testTreeWidget.py
Normal file
35
QTreeWidget/testTreeWidget.py
Normal file
|
@ -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_())
|
Loading…
Reference in a new issue