0
我想获得多选的文件夹路径。我只想得到点击时突出显示的那些。理想情况下,一个列表将交互更新。我的意思是,如果一个文件夹被取消选择,它会自动从列表中删除。QTreeView:获取仅高亮显示的项目列表(多选)
下面是QTreeView的一个例子...请问您能提供支持吗?
谢谢
from PyQt4 import QtCore, QtGui
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.resize(1150, 905)
self.gridLayout_2 = QtGui.QGridLayout(Dialog)
self.groupBox = QtGui.QGroupBox(Dialog)
self.gridLayout = QtGui.QGridLayout(self.groupBox)
self.treeView = QtGui.QTreeView(self.groupBox)
self.gridLayout.addWidget(self.treeView, 0, 0, 1, 1)
self.gridLayout_2.addWidget(self.groupBox, 0, 0, 1, 2)
self.fileSystemModel = QtGui.QFileSystemModel(self.treeView)
self.fileSystemModel.setFilter(QtCore.QDir.AllDirs | QtCore.QDir.NoDotAndDotDot | QtCore.QDir.AllEntries)
self.fileSystemModel.setReadOnly(True)
self.root = self.fileSystemModel.setRootPath('/home/')
self.treeView.setModel(self.fileSystemModel)
self.treeView.setRootIndex(self.root)
self.treeView.setSelectionMode(QtGui.QAbstractItemView.ContiguousSelection)
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_())
看起来不错!谢谢。 :) – user3046026