| 37 | |
| 38 | |
| 39 | class FileManager(QWidget): # type: ignore |
| 40 | def __init__(self, *args, **kwargs): |
| 41 | super(FileManager, self).__init__(*args, **kwargs) |
| 42 | self.resize(800, 600) |
| 43 | self._view = QColumnView(self) |
| 44 | self._btn = QPushButton("确定", self) |
| 45 | layout = QGridLayout(self) |
| 46 | layout.addWidget(self._view, 0, 0, 1, 2) |
| 47 | layout.addItem( |
| 48 | QSpacerItem( |
| 49 | 40, |
| 50 | 20, |
| 51 | QSizePolicy.Expanding, |
| 52 | QSizePolicy.Minimum, |
| 53 | ), |
| 54 | 1, |
| 55 | 0, |
| 56 | ) |
| 57 | layout.addWidget(self._btn, 1, 1, 1, 1) |
| 58 | layout.setRowStretch(1, 0) |
| 59 | self._model = QFileSystemModel(self) |
| 60 | self._model.setRootPath("") # 设置根路径 |
| 61 | self._view.setModel(self._model) # type: ignore |
| 62 | self._btn.clicked.connect(self.onAccept) # type: ignore |
| 63 | |
| 64 | def onAccept(self): |
| 65 | path = self._model.filePath(self._view.currentIndex()) |
| 66 | print("path", path) |
| 67 | if path: |
| 68 | QMessageBox.information(self, "提示", "路径:%s" % path) |
| 69 | |
| 70 | |
| 71 | if __name__ == "__main__": |