【发布时间】:2014-10-13 07:42:13
【问题描述】:
我正在开发一个在布局中需要 qtreeview 的 GUI。现在我编写了一个示例代码来了解 qtreeview 的工作原理,但遇到了一个问题。
我的问题是: 1. 它应该只显示给定路径中存在的文件夹。
2.双击 qtreeview 中的文件夹应该在列视图中提供文件夹的内容,所有者也作为列之一(这里我的意思是说,如果我在终端中执行“ll”,我会得到一个包含所有者的列表文件夹)我也想要这些信息。
这是我的代码:
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(1150, 905)
self.gridLayout_2 = QtGui.QGridLayout(Dialog)
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.groupBox = QtGui.QGroupBox(Dialog)
self.groupBox.setObjectName(_fromUtf8("groupBox"))
self.gridLayout = QtGui.QGridLayout(self.groupBox)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.treeView = QtGui.QTreeView(self.groupBox)
self.treeView.setObjectName(_fromUtf8("treeView"))
self.gridLayout.addWidget(self.treeView, 0, 0, 1, 1)
self.columnView = QtGui.QColumnView(self.groupBox)
self.columnView.setObjectName(_fromUtf8("columnView"))
self.gridLayout.addWidget(self.columnView, 0, 1, 1, 1)
self.gridLayout_2.addWidget(self.groupBox, 0, 0, 1, 2)
spacerItem = QtGui.QSpacerItem(1073, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem, 1, 0, 1, 1)
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.gridLayout_2.addWidget(self.pushButton, 1, 1, 1, 1)
self.fileSystemModel = QtGui.QFileSystemModel(self.treeView)
self.fileSystemModel.setFilter(QtCore.QDir.AllDirs | QtCore.QDir.NoDotAndDotDot | QtCore.QDir.AllEntries)
self.fileSystemModel.setReadOnly(False)
self.root = self.fileSystemModel.setRootPath('/home/hamanda/present_wrkng_python')
self.treeView.setModel(self.fileSystemModel)
self.treeView.setRootIndex(self.root)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.groupBox.setTitle(_translate("Dialog", "List of folders", None))
self.pushButton.setText(_translate("Dialog", "Quit", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
请帮我解决这个问题,我是 pyqt 编程新手
【问题讨论】: