2
에 QTreeView를 연결하는 나는,하지만 PyQt5를 사용하여 여기에 설명 된대로 조금 Filebrowser을 만들려면 : Youtube-Video-DescriptionPyQt5 Filebrowser 신호 슬롯 : QColumnview
지금까지 레이아웃이 잘 작동된다. 이제 파일이 왼쪽 QColumnView에 표시되는 기능을 구현하고 싶습니다. QTreeView에서 클릭 된 폴더의 파일을 오른쪽 File-QColumnView에서 볼 수 있습니다. 나는 QColumnView의 QFileSystemModel에 대한 pathindex를 설정하는 올바른 신호를 만드는 방법에 대한 요점을 알지 못한다. 게다가, Folder-QTreeView의 하나의 (이름) 열만 보여줄 수 있다면 더 좋을 것입니다.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QTreeView, QFileSystemModel, QApplication, QColumnView, QDockWidget, QMainWindow, QTextEdit
from PyQt5.QtCore import QDir, Qt
rootpath = QDir.currentPath()
class Browser(QMainWindow):
def __init__(self):
super(Browser, self).__init__()
self.createDockWindows()
self.textEdit = QTextEdit()
self.setCentralWidget(self.textEdit)
def createDockWindows(self):
dock = QDockWidget("Folders", self)
dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
#Code to Create FileView Colums and FolderTree
self.FileView = QtWidgets.QColumnView()
self.FileView.setGeometry(QtCore.QRect(240, 10, 291, 281))
self.FolderTree = QtWidgets.QTreeView()
self.FolderTree.setGeometry(QtCore.QRect(10, 10, 221, 281))
FolderTree = self.FolderTree
#FolderTree.hidecolumn(1),... ?? to show only name column
#include FolderTree to a Dock at the left side
dock.setWidget(FolderTree)
self.addDockWidget(Qt.LeftDockWidgetArea, dock)
#set the model and rootpath for filling the FolderTree from self.ui
dirmodel = QFileSystemModel()
#set filter to show only folders
dirmodel.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
dirmodel.setRootPath(rootpath)
#filemodel and filter for only files on right side
filemodel = QFileSystemModel()
filemodel.setFilter(QDir.NoDotAndDotDot | QDir.Files)
filemodel.setRootPath(rootpath)
FolderView = self.FolderTree
FolderView.setModel(dirmodel)
FolderView.setRootIndex(dirmodel.index(rootpath))
FileView = self.FileView
FileView.setModel(filemodel)
dock = QDockWidget("Files", self)
dock.setWidget(FileView)
self.addDockWidget(Qt.RightDockWidgetArea, dock)
#important lines for the connection, which does not work
self.FolderTree.clicked['QModelIndex'].connect(self.setpathonclick)
def setpathonclick(self):
currentpathindex = self.FolderTree.currentIndex()
self.FileView.setCurrentIndex(currentpathindex)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
w = Browser()
w.resize(640, 480)
w.show()
sys.exit(app.exec_())
마지막 12 개 라인
이 FolderTree 및 FileOverView의 OnClick 연결에 대한 중요한 내용은 다음과 같습니다 다음은 브라우저의 코드입니다.