本文介绍了TypeError的解决方法是什么:QTreeWidget.setModel() is a private method的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Pyqt5 非常陌生,正在尝试构建 GUI.我在 Qdockwidget 下做了一个 QtreeWidget.
当我尝试使用 Qtreewidget 设置 QFileSystemModel 时,python 出现错误:

I am very new to Pyqt5 and am trying to build a GUI. I made a QtreeWidget under Qdockwidget.
When I try to set QFileSystemModel with Qtreewidget, python comes up with an error:

TypeError: QTreeWidget.setModel() 是一个私有方法

下面是我的 .py 文件:

Below is my .py file:

import os
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
#from PyQt5.QtWidgets import QApplication, QFileSystemModel, QTreeView, QWidget, QVBoxLayout,QPushButton, QMessageBox,QDialog,QTableWidget,QTabWidget

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):



        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(722, 366)

        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.gridLayout_5 = QtWidgets.QGridLayout(self.frame)
        self.gridLayout_5.setObjectName("gridLayout_5")
        self.tabWidget = QtWidgets.QTabWidget(self.frame)
        self.tabWidget.setStyleSheet("")
        self.tabWidget.setObjectName("tabWidget")
        self.XSDTree = QtWidgets.QWidget()
        self.XSDTree.setEnabled(True)
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        self.XSDTree.setFont(font)
        self.XSDTree.setAccessibleName("")
        self.XSDTree.setObjectName("XSDTree")
        self.tabWidget.addTab(self.XSDTree, "")
        self.XMLTree = QtWidgets.QWidget()
        self.XMLTree.setObjectName("XMLTree")
        self.tabWidget.addTab(self.XMLTree, "")
        self.gridLayout_5.addWidget(self.tabWidget, 0, 0, 1, 1)
        self.gridLayout.addWidget(self.frame, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 722, 21))
        self.menubar.setObjectName("menubar")
        self.menuMain = QtWidgets.QMenu(self.menubar)
        self.menuMain.setObjectName("menuMain")
        self.menuDB_Connections = QtWidgets.QMenu(self.menuMain)
        self.menuDB_Connections.setObjectName("menuDB_Connections")
        self.menuLoad_Source_File = QtWidgets.QMenu(self.menuMain)
        self.menuLoad_Source_File.setObjectName("menuLoad_Source_File")
        self.menuSettings = QtWidgets.QMenu(self.menubar)
        self.menuSettings.setObjectName("menuSettings")
        self.menuDefault_folder = QtWidgets.QMenu(self.menuSettings)
        self.menuDefault_folder.setObjectName("menuDefault_folder")
        self.menuExecution = QtWidgets.QMenu(self.menubar)
        self.menuExecution.setObjectName("menuExecution")
        self.menuHelp = QtWidgets.QMenu(self.menubar)
        self.menuHelp.setObjectName("menuHelp")
        self.menuView = QtWidgets.QMenu(self.menubar)
        self.menuView.setObjectName("menuView")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.toolBar = QtWidgets.QToolBar(MainWindow)
        self.toolBar.setObjectName("toolBar")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
        self.toolBar_2 = QtWidgets.QToolBar(MainWindow)
        self.toolBar_2.setObjectName("toolBar_2")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_2)
        self.toolBar_3 = QtWidgets.QToolBar(MainWindow)
        self.toolBar_3.setObjectName("toolBar_3")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_3)
        self.toolBar_4 = QtWidgets.QToolBar(MainWindow)
        self.toolBar_4.setObjectName("toolBar_4")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_4)
        self.FileBrowser = QtWidgets.QDockWidget(MainWindow)
        self.FileBrowser.setEnabled(True)
        self.FileBrowser.setFocusPolicy(QtCore.Qt.NoFocus)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/images (45).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.FileBrowser.setWindowIcon(icon)
        self.FileBrowser.setObjectName("FileBrowser")
        self.dockWidgetContents_5 = QtWidgets.QWidget()
        self.dockWidgetContents_5.setObjectName("dockWidgetContents_5")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.dockWidgetContents_5)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.treeWidget_2 = QtWidgets.QTreeWidget(self.dockWidgetContents_5)

        self.treeWidget_2.setObjectName("treeWidget_2")
        self.treeWidget_2.headerItem().setText(0, "1")
        self.gridLayout_2.addWidget(self.treeWidget_2, 1, 0, 1, 1)

        self.model = QtWidgets.QFileSystemModel()
        self.model.setFilter(QtCore.QDir.Files) 
        self.model.setRootPath('')

        self.treeWidget_2.setModel(self.model)
        m = self.treeWidget_2.selectionModel()
        #m.selectionChanged.connect(self.onSelectionChanged)
        self.treeWidget_2.setAnimated(True)
        self.treeWidget_2.setIndentation(8)
        self.treeWidget_2.setSortingEnabled(True)
        self.treeWidget_2.setWindowTitle("Dir View")

        self.lineEdit = QtWidgets.QLineEdit(self.dockWidgetContents_5)
        self.lineEdit.setObjectName("lineEdit")
        self.gridLayout_2.addWidget(self.lineEdit, 0, 0, 1, 1)
        self.FileBrowser.setWidget(self.dockWidgetContents_5)
        MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.FileBrowser)
        self.dockWidget_5 = QtWidgets.QDockWidget(MainWindow)
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/images (2).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.dockWidget_5.setWindowIcon(icon1)
        self.dockWidget_5.setObjectName("dockWidget_5")
        self.dockWidgetContents_6 = QtWidgets.QWidget()
        self.dockWidgetContents_6.setObjectName("dockWidgetContents_6")
        self.gridLayout_4 = QtWidgets.QGridLayout(self.dockWidgetContents_6)
        self.gridLayout_4.setObjectName("gridLayout_4")
        self.listView_2 = QtWidgets.QListView(self.dockWidgetContents_6)
        self.listView_2.setObjectName("listView_2")
        self.gridLayout_4.addWidget(self.listView_2, 0, 0, 1, 1)
        self.dockWidget_5.setWidget(self.dockWidgetContents_6)
        MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.dockWidget_5)
        self.actionOracle = QtWidgets.QAction(MainWindow)
        self.actionOracle.setObjectName("actionOracle")
        self.actionSql_Server = QtWidgets.QAction(MainWindow)
        self.actionSql_Server.setObjectName("actionSql_Server")
        self.actionMySql = QtWidgets.QAction(MainWindow)
        self.actionMySql.setObjectName("actionMySql")
        self.actionSqlite_3 = QtWidgets.QAction(MainWindow)
        self.actionSqlite_3.setObjectName("actionSqlite_3")
        self.actionQuery_Builder = QtWidgets.QAction(MainWindow)
        self.actionQuery_Builder.setObjectName("actionQuery_Builder")
        self.actionCSV_File = QtWidgets.QAction(MainWindow)
        self.actionCSV_File.setObjectName("actionCSV_File")
        self.actionExcel_File = QtWidgets.QAction(MainWindow)
        self.actionExcel_File.setObjectName("actionExcel_File")
        self.actionDefine_NameSpaces = QtWidgets.QAction(MainWindow)
        self.actionDefine_NameSpaces.setObjectName("actionDefine_NameSpaces")
        self.actionSource_Files = QtWidgets.QAction(MainWindow)
        self.actionSource_Files.setObjectName("actionSource_Files")
        self.actionFor_Target_Files = QtWidgets.QAction(MainWindow)
        self.actionFor_Target_Files.setObjectName("actionFor_Target_Files")
        self.actionGenerag_XML_Document = QtWidgets.QAction(MainWindow)
        self.actionGenerag_XML_Document.setObjectName("actionGenerag_XML_Document")
        self.actionEncapsulation_and_Encryption = QtWidgets.QAction(MainWindow)
        self.actionEncapsulation_and_Encryption.setObjectName("actionEncapsulation_and_Encryption")
        self.actionExit_Application = QtWidgets.QAction(MainWindow)
        self.actionExit_Application.setObjectName("actionExit_Application")
        self.actionOnline_Documentation = QtWidgets.QAction(MainWindow)
        self.actionOnline_Documentation.setObjectName("actionOnline_Documentation")
        self.actionSearch_Topics = QtWidgets.QAction(MainWindow)
        self.actionSearch_Topics.setObjectName("actionSearch_Topics")
        self.actionActivate_Licence = QtWidgets.QAction(MainWindow)
        self.actionActivate_Licence.setObjectName("actionActivate_Licence")
        self.actionAbout = QtWidgets.QAction(MainWindow)
        self.actionAbout.setObjectName("actionAbout")
        self.actionLoad_CSV_File_2 = QtWidgets.QAction(MainWindow)
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/17_-_CSV_File_Flat-128.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionLoad_CSV_File_2.setIcon(icon2)
        self.actionLoad_CSV_File_2.setObjectName("actionLoad_CSV_File_2")
        self.actionLoad_Excel_File = QtWidgets.QAction(MainWindow)
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/698375-icon-96-document-file-xls-128.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionLoad_Excel_File.setIcon(icon3)
        self.actionLoad_Excel_File.setObjectName("actionLoad_Excel_File")
        self.actionDataBase_Connections_Configuration = QtWidgets.QAction(MainWindow)
        self.actionDataBase_Connections_Configuration.setIcon(icon1)
        self.actionDataBase_Connections_Configuration.setObjectName("actionDataBase_Connections_Configuration")
        self.actionQuery_Builder_2 = QtWidgets.QAction(MainWindow)
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/download (2).png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionQuery_Builder_2.setIcon(icon4)
        self.actionQuery_Builder_2.setObjectName("actionQuery_Builder_2")
        self.actionMap_XSD_Schema = QtWidgets.QAction(MainWindow)
        icon5 = QtGui.QIcon()
        icon5.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/download (1).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionMap_XSD_Schema.setIcon(icon5)
        self.actionMap_XSD_Schema.setObjectName("actionMap_XSD_Schema")
        self.actionDefine_Source_Folder = QtWidgets.QAction(MainWindow)
        self.actionDefine_Source_Folder.setIcon(icon)
        self.actionDefine_Source_Folder.setObjectName("actionDefine_Source_Folder")
        self.actionDefine_Target_Folder = QtWidgets.QAction(MainWindow)
        icon6 = QtGui.QIcon()
        icon6.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/download (21).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionDefine_Target_Folder.setIcon(icon6)
        self.actionDefine_Target_Folder.setObjectName("actionDefine_Target_Folder")
        self.actionGenerate_XML_Document = QtWidgets.QAction(MainWindow)
        icon7 = QtGui.QIcon()
        icon7.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/download (1).png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionGenerate_XML_Document.setIcon(icon7)
        self.actionGenerate_XML_Document.setObjectName("actionGenerate_XML_Document")
        self.actionEncryption_and_Encapsulation = QtWidgets.QAction(MainWindow)
        icon8 = QtGui.QIcon()
        icon8.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/download (10).png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionEncryption_and_Encapsulation.setIcon(icon8)
        self.actionEncryption_and_Encapsulation.setObjectName("actionEncryption_and_Encapsulation")
        self.actionPreview_XML_Document = QtWidgets.QAction(MainWindow)
        self.actionPreview_XML_Document.setObjectName("actionPreview_XML_Document")
        self.actionPreview_in_IE = QtWidgets.QAction(MainWindow)
        icon9 = QtGui.QIcon()
        icon9.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/images (11).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionPreview_in_IE.setIcon(icon9)
        self.actionPreview_in_IE.setObjectName("actionPreview_in_IE")
        self.actionMail_Setup = QtWidgets.QAction(MainWindow)
        self.actionMail_Setup.setObjectName("actionMail_Setup")
        self.actionConfigure_Email = QtWidgets.QAction(MainWindow)
        icon10 = QtGui.QIcon()
        icon10.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/images (26).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionConfigure_Email.setIcon(icon10)
        self.actionConfigure_Email.setObjectName("actionConfigure_Email")
        self.actionSend_Mail = QtWidgets.QAction(MainWindow)
        self.actionSend_Mail.setObjectName("actionSend_Mail")
        self.actionSend_Mail_2 = QtWidgets.QAction(MainWindow)
        icon11 = QtGui.QIcon()
        icon11.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/images (27).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionSend_Mail_2.setIcon(icon11)
        self.actionSend_Mail_2.setObjectName("actionSend_Mail_2")
        self.actionHelp = QtWidgets.QAction(MainWindow)
        icon12 = QtGui.QIcon()
        icon12.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/images (46).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionHelp.setIcon(icon12)
        self.actionHelp.setObjectName("actionHelp")
        self.actionAbout_Us = QtWidgets.QAction(MainWindow)
        icon13 = QtGui.QIcon()
        icon13.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/images (12).png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionAbout_Us.setIcon(icon13)
        self.actionAbout_Us.setObjectName("actionAbout_Us")
        self.actionFollow_Us_On_Social_Media = QtWidgets.QAction(MainWindow)
        icon14 = QtGui.QIcon()
        icon14.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/images (52).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionFollow_Us_On_Social_Media.setIcon(icon14)
        self.actionFollow_Us_On_Social_Media.setObjectName("actionFollow_Us_On_Social_Media")
        self.actionActivate_Licence_2 = QtWidgets.QAction(MainWindow)
        icon15 = QtGui.QIcon()
        icon15.addPixmap(QtGui.QPixmap(":/ToolBarIco/Resources/Icons/images (44).jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionActivate_Licence_2.setIcon(icon15)
        self.actionActivate_Licence_2.setObjectName("actionActivate_Licence_2")
        self.actionFile_Explorer = QtWidgets.QAction(MainWindow)
        self.actionFile_Explorer.setCheckable(True)
        self.actionFile_Explorer.setChecked(True)
        self.actionFile_Explorer.setObjectName("actionFile_Explorer")
        self.actionDB_Connections = QtWidgets.QAction(MainWindow)
        self.actionDB_Connections.setObjectName("actionDB_Connections")
        self.menuDB_Connections.addAction(self.actionOracle)
        self.menuDB_Connections.addSeparator()
        self.menuDB_Connections.addAction(self.actionSql_Server)
        self.menuDB_Connections.addSeparator()
        self.menuDB_Connections.addAction(self.actionMySql)
        self.menuDB_Connections.addSeparator()
        self.menuDB_Connections.addAction(self.actionSqlite_3)
        self.menuLoad_Source_File.addAction(self.actionCSV_File)
        self.menuLoad_Source_File.addSeparator()
        self.menuLoad_Source_File.addAction(self.actionExcel_File)
        self.menuMain.addAction(self.menuLoad_Source_File.menuAction())
        self.menuMain.addSeparator()
        self.menuMain.addAction(self.menuDB_Connections.menuAction())
        self.menuMain.addSeparator()
        self.menuMain.addAction(self.actionQuery_Builder)
        self.menuMain.addSeparator()
        self.menuMain.addAction(self.actionExit_Application)
        self.menuDefault_folder.addAction(self.actionSource_Files)
        self.menuDefault_folder.addSeparator()
        self.menuDefault_folder.addAction(self.actionFor_Target_Files)
        self.menuSettings.addAction(self.actionDefine_NameSpaces)
        self.menuSettings.addSeparator()
        self.menuSettings.addAction(self.menuDefault_folder.menuAction())
        self.menuSettings.addSeparator()
        self.menuSettings.addAction(self.actionMail_Setup)
        self.menuExecution.addAction(self.actionGenerag_XML_Document)
        self.menuExecution.addSeparator()
        self.menuExecution.addAction(self.actionEncapsulation_and_Encryption)
        self.menuExecution.addSeparator()
        self.menuExecution.addAction(self.actionPreview_XML_Document)
        self.menuExecution.addSeparator()
        self.menuExecution.addAction(self.actionSend_Mail)
        self.menuHelp.addAction(self.actionOnline_Documentation)
        self.menuHelp.addSeparator()
        self.menuHelp.addAction(self.actionSearch_Topics)
        self.menuHelp.addSeparator()
        self.menuHelp.addAction(self.actionActivate_Licence)
        self.menuHelp.addSeparator()
        self.menuHelp.addAction(self.actionAbout)
        self.menuView.addAction(self.actionFile_Explorer)
        self.menuView.addSeparator()
        self.menuView.addAction(self.actionDB_Connections)
        self.menubar.addAction(self.menuMain.menuAction())
        self.menubar.addAction(self.menuSettings.menuAction())
        self.menubar.addAction(self.menuExecution.menuAction())
        self.menubar.addAction(self.menuView.menuAction())
        self.menubar.addAction(self.menuHelp.menuAction())
        self.toolBar.addAction(self.actionLoad_CSV_File_2)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionLoad_Excel_File)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionDataBase_Connections_Configuration)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionQuery_Builder_2)
        self.toolBar_2.addAction(self.actionMap_XSD_Schema)
        self.toolBar_2.addSeparator()
        self.toolBar_2.addAction(self.actionDefine_Source_Folder)
        self.toolBar_2.addSeparator()
        self.toolBar_2.addAction(self.actionDefine_Target_Folder)
        self.toolBar_2.addSeparator()
        self.toolBar_2.addAction(self.actionConfigure_Email)
        self.toolBar_3.addAction(self.actionGenerate_XML_Document)
        self.toolBar_3.addSeparator()
        self.toolBar_3.addAction(self.actionPreview_in_IE)
        self.toolBar_3.addSeparator()
        self.toolBar_3.addAction(self.actionEncryption_and_Encapsulation)
        self.toolBar_3.addSeparator()
        self.toolBar_3.addAction(self.actionSend_Mail_2)
        self.toolBar_4.addAction(self.actionHelp)
        self.toolBar_4.addSeparator()
        self.toolBar_4.addAction(self.actionAbout_Us)
        self.toolBar_4.addSeparator()
        self.toolBar_4.addAction(self.actionFollow_Us_On_Social_Media)
        self.toolBar_4.addAction(self.actionActivate_Licence_2)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.XSDTree.setToolTip(_translate("MainWindow", "<html><head/><body><p>View XSD Structure</p></body></html>"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.XSDTree), _translate("MainWindow", "Tab 1"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.XMLTree), _translate("MainWindow", "Tab 2"))
        self.menuMain.setTitle(_translate("MainWindow", "Main"))
        self.menuDB_Connections.setTitle(_translate("MainWindow", "DB Connections"))
        self.menuLoad_Source_File.setTitle(_translate("MainWindow", "Load Source File"))
        self.menuSettings.setTitle(_translate("MainWindow", "Settings"))
        self.menuDefault_folder.setTitle(_translate("MainWindow", "Default folder"))
        self.menuExecution.setTitle(_translate("MainWindow", "Execution"))
        self.menuHelp.setTitle(_translate("MainWindow", "Help"))
        self.menuView.setTitle(_translate("MainWindow", "View"))
        self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar"))
        self.toolBar_2.setWindowTitle(_translate("MainWindow", "toolBar_2"))
        self.toolBar_3.setWindowTitle(_translate("MainWindow", "toolBar_3"))
        self.toolBar_4.setWindowTitle(_translate("MainWindow", "toolBar_4"))
        self.lineEdit.setPlaceholderText(_translate("MainWindow", "Filter"))
        self.actionOracle.setText(_translate("MainWindow", "Oracle"))
        self.actionSql_Server.setText(_translate("MainWindow", "Sql Server"))
        self.actionMySql.setText(_translate("MainWindow", "MySql"))
        self.actionSqlite_3.setText(_translate("MainWindow", "Sqlite 3"))
        self.actionQuery_Builder.setText(_translate("MainWindow", "Query Builder"))
        self.actionCSV_File.setText(_translate("MainWindow", "CSV File"))
        self.actionExcel_File.setText(_translate("MainWindow", "Excel File"))
        self.actionDefine_NameSpaces.setText(_translate("MainWindow", "Define NameSpaces"))
        self.actionSource_Files.setText(_translate("MainWindow", "For Source Files"))
        self.actionFor_Target_Files.setText(_translate("MainWindow", "For Target Files"))
        self.actionGenerag_XML_Document.setText(_translate("MainWindow", "Generag XML Document"))
        self.actionEncapsulation_and_Encryption.setText(_translate("MainWindow", "Encapsulation and Encryption"))
        self.actionExit_Application.setText(_translate("MainWindow", "Exit Application"))
        self.actionOnline_Documentation.setText(_translate("MainWindow", "Documentation"))
        self.actionSearch_Topics.setText(_translate("MainWindow", "Search Topics"))
        self.actionActivate_Licence.setText(_translate("MainWindow", "Activate Licence"))
        self.actionAbout.setText(_translate("MainWindow", "About"))
        self.actionLoad_CSV_File_2.setText(_translate("MainWindow", "Load CSV File"))
        self.actionLoad_CSV_File_2.setToolTip(_translate("MainWindow", "Load CSV File"))
        self.actionLoad_Excel_File.setText(_translate("MainWindow", "Load Excel File"))
        self.actionLoad_Excel_File.setToolTip(_translate("MainWindow", "Load Excel File"))
        self.actionDataBase_Connections_Configuration.setText(_translate("MainWindow", "DataBase Connections Configuration"))
        self.actionDataBase_Connections_Configuration.setToolTip(_translate("MainWindow", "DataBase Connections Configuration"))
        self.actionQuery_Builder_2.setText(_translate("MainWindow", "Query Builder"))
        self.actionQuery_Builder_2.setToolTip(_translate("MainWindow", "Query Builder"))
        self.actionMap_XSD_Schema.setText(_translate("MainWindow", "Map XSD Schema"))
        self.actionMap_XSD_Schema.setToolTip(_translate("MainWindow", "Map XSD Schema"))
        self.actionDefine_Source_Folder.setText(_translate("MainWindow", "Define Source Folder"))
        self.actionDefine_Source_Folder.setToolTip(_translate("MainWindow", "Define Source Folder"))
        self.actionDefine_Target_Folder.setText(_translate("MainWindow", "Define Target Folder"))
        self.actionDefine_Target_Folder.setToolTip(_translate("MainWindow", "Define Target Folder"))
        self.actionGenerate_XML_Document.setText(_translate("MainWindow", "Generate XML Document"))
        self.actionGenerate_XML_Document.setToolTip(_translate("MainWindow", "Generate XML Document"))
        self.actionEncryption_and_Encapsulation.setText(_translate("MainWindow", "Encryption and Encapsulation"))
        self.actionEncryption_and_Encapsulation.setToolTip(_translate("MainWindow", "Encryption and Encapsulation"))
        self.actionPreview_XML_Document.setText(_translate("MainWindow", "Preview XML Document"))
        self.actionPreview_in_IE.setText(_translate("MainWindow", "Preview in IE"))
        self.actionPreview_in_IE.setToolTip(_translate("MainWindow", "Preview in IE"))
        self.actionMail_Setup.setText(_translate("MainWindow", "Mail Setup"))
        self.actionConfigure_Email.setText(_translate("MainWindow", "Configure Email"))
        self.actionConfigure_Email.setToolTip(_translate("MainWindow", "Configure Email"))
        self.actionSend_Mail.setText(_translate("MainWindow", "Send Mail"))
        self.actionSend_Mail_2.setText(_translate("MainWindow", "Send Mail"))
        self.actionSend_Mail_2.setToolTip(_translate("MainWindow", "Send Mail"))
        self.actionHelp.setText(_translate("MainWindow", "Help"))
        self.actionHelp.setToolTip(_translate("MainWindow", "Help"))
        self.actionAbout_Us.setText(_translate("MainWindow", "About Us"))
        self.actionAbout_Us.setToolTip(_translate("MainWindow", "About Us"))
        self.actionFollow_Us_On_Social_Media.setText(_translate("MainWindow", "Follow Us On Social Media"))
        self.actionFollow_Us_On_Social_Media.setToolTip(_translate("MainWindow", "Follow Us On Social Media"))
        self.actionActivate_Licence_2.setText(_translate("MainWindow", "Activate Licence"))
        self.actionActivate_Licence_2.setToolTip(_translate("MainWindow", "Activate Licence"))
        self.actionFile_Explorer.setText(_translate("MainWindow", "File Explorer"))
        self.actionDB_Connections.setText(_translate("MainWindow", "DB Connections"))

import ProjectResource

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

推荐答案

QTreeWidget 只有一个只读模型,所以你不能用另一个模型替换它,所以在你的情况下,错误消息试图证明它.

The QTreeWidget only has a read-only model so you cannot replace it with another model, so in your case the error message tries to evidence it.

您的情况的解决方案是将其更改为 QTreeView:

The solution in your case is to change it to QTreeView:

self.treeWidget_2 = QtWidgets.QTreeView(self.dockWidgetContents_5)

此外,还必须删除以下代码行:

In addition, you must also delete the following line of code:

self.treeWidget_2.headerItem().setText(0, "1")

这篇关于TypeError的解决方法是什么:QTreeWidget.setModel() is a private method的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 00:55