通过QDockWidget
# dock window project self.projectdock = QtWidgets.QDockWidget(self.tr("Project"), self) self.projectdock.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetClosable | QtWidgets.QDockWidget.DockWidgetFloatable) self.projectdock.setAllowedAreas( QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea) self.projModel = QtWidgets.QFileSystemModel() self.projTree = QtWidgets.QTreeView() self.projTree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.projTree.customContextMenuRequested.connect( self.projTree_contextmenu_handler) self.projTree.setModel(self.projModel) self.projTree.setColumnHidden(1, True) self.projTree.setColumnHidden(2, True) self.projTree.setColumnHidden(3, True) self.projTree.setHeaderHidden(True) # bind double click handler self.projTree.doubleClicked.connect( self.__tree_double_clicked_handler) self.projectdock.setWidget(self.projTree) self.projectdock.closeEvent = self.__projectdock_closeEvent_handler self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.projectdock)