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