我得到POO,python和PyQt慢,我有一个问题,以了解有关传递参数和属性的东西。QTreeView,类,参数,实例和属性
我在网上找到了一个处理QTreeView的代码(见下面),我不明白Index是如何传入showPath()的。另外为什么self.filename和self.filepath不会传递给实例?
我希望我已经够清楚了......非常感谢。
from PyQt4 import QtGui
class TreeViewWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(TreeViewWidget, self).__init__(parent)
self.model = QtGui.QFileSystemModel(self)
self.model.setRootPath(rootpath)
self.indexRoot = self.model.index(self.model.rootPath())
self.treeView = QtGui.QTreeView(self)
self.treeView.setExpandsOnDoubleClick(False)
self.treeView.setModel(self.model)
self.treeView.setRootIndex(self.indexRoot)
self.treeView.setColumnWidth(0,220)
self.treeView.clicked.connect(self.showPath)
self.treeView.doubleClicked.connect(self.openQuickLook)
self.labelFileName = QtGui.QLabel(self)
self.labelFileName.setText("File Name:")
self.lineEditFileName = QtGui.QLineEdit(self)
self.labelFilePath = QtGui.QLabel(self)
self.labelFilePath.setText("File Path:")
self.lineEditFilePath = QtGui.QLineEdit(self)
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.addWidget(self.labelFileName, 0, 0)
self.gridLayout.addWidget(self.lineEditFileName, 0, 1)
self.gridLayout.addWidget(self.labelFilePath, 1, 0)
self.gridLayout.addWidget(self.lineEditFilePath, 1, 1)
self.layout = QtGui.QVBoxLayout(self)
self.layout.addLayout(self.gridLayout)
self.layout.addWidget(self.treeView)
def givePathName(self, index):
indexItem = self.model.index(index.row(), 0, index.parent())
self.filename = self.model.fileName(indexItem)
self.filepath = self.model.filePath(indexItem)
def showPath(self, index):
self.givePathName(index)
self.lineEditFileName.setText(self.filename)
self.lineEditFilePath.setText(self.filepath)