pyqt编写GUI界面时点击Qtreewidget的节点时显示程序未响应

import sys
from PyQt5.QtWidgets import *
from Newport1 import *

class Mymainwindow(QMainWindow):

item_list = []
i = 0
dict2 = {}

def __init__(self):
    super().__init__()
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)
    self.show()
    self.ui.btn_line.clicked.connect(self.newline)
    self.ui.treeWidget.clicked.connect(self.onClicked1)


def addtabwidget(self):
    tabWidget_line = QTabWidget()
    sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
    sizePolicy.setHeightForWidth(tabWidget_line.sizePolicy().hasHeightForWidth())
    tabWidget_line.setSizePolicy(sizePolicy)
    tabWidget_line.setMinimumSize(QtCore.QSize(250, 0))
    tabWidget_line.setMaximumSize(QtCore.QSize(250, 16777215))
    tabWidget_line.setElideMode(QtCore.Qt.ElideNone)
    tabWidget_line.setVisible(False)
    # self.ui.verticalLayout_27.addWidget(tabWidget_line)
    return tabWidget_line

def newline(self):
    root = QTreeWidgetItem(self.ui.treeWidget)
    root.setText(0, "Line"+str(self.i))
    # tabWidget_line = self.addtabwidget()
    # try:
    #     item = ("Line"+str(self.i), tabWidget_line)
    #     self.item_list.append(item)
    #     self.dict2 = dict(self.item_list)
    # except:
    #     pass
    # self.i = self.i +1
    # return self.dict2

# def root(self):
#     tabWidget_line = self.newline()
#     print(tabWidget_line)
#     self.ui.treeWidget.clicked.connect(lambda: self.onClicked1())

def onClicked1(self):
    print(0)
    # print(self.dict2)
    # item = self.ui.treeWidget.currentItem().text(0)
    # data1 = self.dict2[item]
    # print(data1)
    # for i in range(self.ui.verticalLayout_27.count()):
    #     print(self.ui.verticalLayout_27.itemAt(i).widget())
    #     if self.ui.verticalLayout_27.itemAt(i).widget() != data1:
    #         # self.ui.verticalLayout_27.itemAt(i).widget().setVisible(False)
    #         self.ui.verticalLayout_27.removeWidget(self.ui.verticalLayout_27.itemAt(i).widget())
    #         self.ui.verticalLayout_27.addWidget(data1)
    # data1.show()
    # print(item, data1)
    # return item

if name == "__main__":
app = QApplication(sys.argv)
W = Mymainwindow()
W.show()
sys.exit(app.exec_())


不知道问题出在哪里,求教

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!