-
Notifications
You must be signed in to change notification settings - Fork 0
/
tui.py
159 lines (113 loc) · 4.47 KB
/
tui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# # coding:utf-8
# import sys
# from PyQt6.QtCore import Qt
# from PyQt6.QtGui import QFileSystemModel
# from PyQt6.QtWidgets import QApplication, QWidget, QTreeWidgetItem, QHBoxLayout
# from qfluentwidgets import TreeWidget, setTheme, Theme, TreeView
# class Demo(QWidget):
# """ 树形控件演示 """
# def __init__(self):
# super().__init__()
# self.hBoxLayout = QHBoxLayout(self)
# self.setStyleSheet("Demo{background:rgb(255,255,255)}")
# # setTheme(Theme.DARK)
# self.view = TreeView(self)
# model = QFileSystemModel()
# model.setRootPath('.')
# self.view.setModel(model)
# self.hBoxLayout.addWidget(self.view)
# self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
# self.resize(700, 600)
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# w = Demo()
# w.show()
# sys.exit(app.exec())
# coding:utf-8
# import sys
# from PyQt6.QtCore import Qt
# from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout
# from qfluentwidgets import IndeterminateProgressBar, ProgressBar
# class Demo(QWidget):
# def __init__(self):
# super().__init__()
# self.vBoxLayout = QVBoxLayout(self)
# self.progressBar = ProgressBar(self)
# # self.inProgressBar = IndeterminateProgressBar(self)
# self.progressBar.setValue(50)
# self.vBoxLayout.addWidget(self.progressBar)
# # self.vBoxLayout.addWidget(self.inProgressBar)
# self.vBoxLayout.setContentsMargins(30, 30, 30, 30)
# self.resize(400, 400)
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# w = Demo()
# w.show()
# app.exec()
# from PyQt6.QtCore import QTimer
# from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel
# # 创建应用程序和主窗口
# app = QApplication([])
# window = QMainWindow()
# # 创建 QLabel 用于显示动态内容
# label = QLabel("Initial Text")
# window.setCentralWidget(label)
# # 创建 QTimer
# timer = QTimer()
# timer.setInterval(1000) # 每隔 1 秒触发一次定时器
# # 定义定时器触发时执行的槽函数
# def update_label():
# label.setText("Updated Text")
# # 将槽函数与定时器的 timeout 信号关联
# timer.timeout.connect(update_label)
# # 启动定时器
# timer.start()
# # 显示主窗口
# window.show()
# app.exec()
# from treelib import Tree
# tree = Tree()
# tree.create_node("A", "a") # 创建根节点
# tree.create_node("B", "b", parent="a") # 创建子节点
# tree.create_node("C", "c", parent="a") # 创建另一个子节点
# lists = tree.all_nodes()
# for item in lists:
# print(tree.children(item.identifier))
# a = []
# if a:
# print("1")
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QTreeView, QVBoxLayout, QWidget
from PyQt6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon, QFileSystemModel, QStandardItemModel,
QImage, QKeySequence, QLinearGradient, QPainter, QStandardItem,
QPalette, QPixmap, QRadialGradient, QTransform)
from PyQt6.QtCore import Qt
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# 创建一个QTreeView对象
self.tree_view = QTreeView(self)
self.tree_view.setHeaderHidden(True)
self.tree_view.setSortingEnabled(True)
self.tree_view.setGeometry(0,0,200,200)
# 创建一个QStandardItemModel对象,用于存储数据
self.model = QStandardItemModel()
self.tree_view.setModel(self.model)
# 创建根节点并添加到模型中
root_item = self.model.invisibleRootItem()
root_item.appendRow([QStandardItem("Parent Item"), QStandardItem("Child Item 1"), QStandardItem("Child Item 2")])
# 创建子节点并添加到模型中
child_item = root_item.child(0)
child_item.appendRow([QStandardItem("Grandchild Item 1"), QStandardItem("Grandchild Item 2")])
# 创建根节点并添加到模型中
root_item2 = self.model.invisibleRootItem()
root_item2.appendRow([QStandardItem("dddParent Item"), QStandardItem("Child Item 1"), QStandardItem("Child Item 2")])
# 创建子节点并添加到模型中
child_item2 = root_item2.child(1)
child_item2.appendRow([QStandardItem("Grandchild Item 1"), QStandardItem("Grandchild Item 2")])
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())